Skip to content

Commit

Permalink
feat: more color options
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Dec 19, 2024
1 parent 002c168 commit b2b14de
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 27 deletions.
12 changes: 12 additions & 0 deletions docs/stories/aIntro.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,15 @@ export const WithNoSpecialColumns = {
enableExport: false,
} satisfies TableProps<Item>,
};

export const DarkMode = {
args: {
...Primary.args,
colors: {
background: '#333',
text: '#fff',
border: '#555',
borderLight: '#444',
},
} satisfies TableProps<Item>,
};
13 changes: 12 additions & 1 deletion src/components/autoFocusTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@ export function AutoFocusTextField(props: Omit<Props, 'inputRef'>) {
}
}, [isActive]);

return <TextField {...props} inputRef={ref} />;
return (
<TextField
{...props}
inputRef={ref}
css={{
input: {
backgroundColor: 'inherit',
color: 'inherit',
},
}}
/>
);
}
7 changes: 7 additions & 0 deletions src/components/dateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export function DateInput({
borderBottom: '2px solid transparent',
outline: 'none',
fontSize: 'inherit',
backgroundColor: 'inherit',
color: 'inherit',

'::placeholder': {
color: 'inherit',
opacity: 0.5,
},

'&:focus': {
borderBottom: '2px solid var(--primaryMain)',
Expand Down
23 changes: 18 additions & 5 deletions src/components/datePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from 'react';
import { useTheme } from '../hooks/useTheme';
import { defaults } from '../misc/defaults';
import { gray } from '../theme/defaultTheme/defaultClasses';
import { useCssVariables } from '../theme/useCssVariables';
import { DateInput } from './dateInput';
import { Text } from './text';
Expand Down Expand Up @@ -285,9 +284,10 @@ export function DatePicker(props: DatePickerProps) {
background: 'transparent',
cursor: disabled ? undefined : 'pointer',
font: 'inherit',
color: 'inherit',
},
(prevMonth || nextMonth) && {
color: gray,
color: 'var(--date-picker-disemphasized, #bdbdbd)',
},
today && {
outline: '1px solid var(--secondaryMain)',
Expand Down Expand Up @@ -351,6 +351,9 @@ export function DatePicker(props: DatePickerProps) {
key={index}
variant="text"
type="button"
css={{
color: 'inherit',
}}
onClick={() => {
setDirty(undefined);

Expand Down Expand Up @@ -435,7 +438,14 @@ export function DatePicker(props: DatePickerProps) {
}, [locale]);

return (
<div css={cssVariables}>
<div
css={[
cssVariables,
{
color: 'var(--table-text-color)',
},
]}
>
<div
css={{
display: 'grid',
Expand Down Expand Up @@ -499,7 +509,8 @@ export function DatePicker(props: DatePickerProps) {
css={{
justifySelf: 'center',
padding: 10,
borderRight: `1px solid ${gray}`,
borderRight:
'1px solid var(--date-picker-separator, var(--table-border, #bdbdbd))',
}}
>
<Text id="calendarWeek" />
Expand Down Expand Up @@ -539,7 +550,9 @@ export function DatePicker(props: DatePickerProps) {
background: 'transparent',
cursor: weekDisabled ? undefined : 'pointer',
font: 'inherit',
borderRight: `1px solid ${gray}`,
borderRight:
'1px solid var(--date-picker-separator, var(--table-border, #bdbdbd))',
color: 'inherit',
}}
onClick={() => {
if (weekDisabled) {
Expand Down
6 changes: 6 additions & 0 deletions src/components/numberField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export function NumberField({
setValue(undefined);
}}
{...textFieldProps}
css={{
input: {
backgroundColor: 'inherit',
color: 'inherit',
},
}}
/>
);
}
7 changes: 6 additions & 1 deletion src/components/selectFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ export function SelectFilter<T, V, F extends SerializableValue>({
disabled={value.size === 0}
onClick={() => onChange(new Set())}
variant="outlined"
css={{ justifyContent: 'center', width: '100%', marginBottom: 'var(--spacing)' }}
css={{
justifyContent: 'center',
width: '100%',
marginBottom: 'var(--spacing)',
color: 'inherit',
}}
>
{deselectAll}
</Button>
Expand Down
5 changes: 2 additions & 3 deletions src/theme/defaultTheme/button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { TableTheme } from '../../types';
import { darkGray, lightGray } from './defaultClasses';

export const Button: TableTheme['components']['Button'] = ({
startIcon,
Expand Down Expand Up @@ -30,10 +29,10 @@ export const Button: TableTheme['components']['Button'] = ({
},
},
variant === 'outlined' && {
border: `1px solid ${darkGray}`,
border: '1px solid var(--table-button-border, var(--table-border, #777777))',

'&:disabled': {
borderColor: lightGray,
borderColor: 'var(--table-button-border-disabled, #eeeeee)',
},
},
variant === 'contained' && {
Expand Down
27 changes: 12 additions & 15 deletions src/theme/defaultTheme/defaultClasses.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { css } from '@emotion/react';

export const white = '#ffffff';
export const lightGray = '#eeeeee';
export const gray = '#bdbdbd';
export const darkGray = '#777';

const cell = css({
display: 'flex',
alignItems: 'center',
borderBottom: `1px solid #dfe2e9`,
borderBottom: '1px solid var(--table-border-light-color)',
whiteSpace: 'nowrap',
overflow: 'hidden',
background: 'white',
background: 'var(--table-background-color)',

'&:not(:empty)': {
padding: `calc(var(--spacing) * 0.1) calc(2 * var(--spacing))`,
Expand All @@ -22,16 +17,18 @@ export const defaultClasses = {
table: css({
position: 'relative',
display: 'grid',
color: 'var(--table-text-color)',
}),

cell,

cellFill: css({
borderBottom: `1px solid ${lightGray}`,
borderBottom: '1px solid var(--table-border-light-color)',
background: 'var(--table-background-color)',
}),

headerCell: css(cell, {
borderBottom: `1px solid #c9cfda`,
borderBottom: '1px solid var(--table-border-color)',

'&:not(:empty)': {
padding: `var(--spacing) 0 var(--spacing) calc(2 * var(--spacing))`,
Expand All @@ -40,7 +37,7 @@ export const defaultClasses = {

footerCell: css(cell, {
padding: `var(--spacing) calc(2 * var(--spacing))`,
borderTop: `1px solid #c9cfda`,
borderTop: '1px solid var(--table-border-color)',
borderBottom: 'none',
}),

Expand All @@ -61,13 +58,13 @@ export const defaultClasses = {
}),

headerFill: css({
borderBottom: `1px solid #c9cfda`,
background: white,
borderBottom: '1px solid var(--table-border-color)',
background: 'var(--table-background-color)',
}),

footerFill: css({
borderTop: `1px solid #c9cfda`,
background: white,
borderTop: '1px solid var(--table-border-color)',
background: 'var(--table-background-color)',
}),

text: css({
Expand All @@ -79,7 +76,7 @@ export const defaultClasses = {
card: css({
borderRadius: 4,
boxShadow: '0px 3px 14px 2px rgb(0 0 0 / 12%)',
background: 'white',
background: 'var(--table-background-color)',
}),

clearFiltersButton: css({
Expand Down
4 changes: 4 additions & 0 deletions src/theme/defaultTheme/defaultColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ export const defaultColors: TableTheme['colors'] = {
primary: { main: '#1976d2', light: '#42a5f5', contrastText: '#fff' },
secondary: { main: '#9c27b0', light: '#ba68c8', contrastText: '#fff' },
blocked: { main: '#f44336', light: '#f26257', contrastText: '#fff' },
background: '#ffffff',
text: 'inherit',
border: '#777',
borderLight: '#eee',
};
1 change: 1 addition & 0 deletions src/theme/defaultTheme/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const Popover: TableTheme['components']['Popover'] = ({
...position,
zIndex: zIndex + 1,
overflowY: 'auto',
color: 'var(--table-text-color)',
},
hidden && { display: 'none' },
!position && { visibility: 'hidden' },
Expand Down
3 changes: 1 addition & 2 deletions src/theme/defaultTheme/textField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState } from 'react';
import type { TableTheme } from '../../types';
import { darkGray } from './defaultClasses';

export const TextField: TableTheme['components']['TextField'] = ({
startIcon,
Expand All @@ -20,7 +19,7 @@ export const TextField: TableTheme['components']['TextField'] = ({
flex: 1,
display: 'flex',
alignItems: 'center',
border: `1px solid ${darkGray}`,
border: '1px solid var(--table-textfield-border, var(--table-border, #777777))',
borderRadius: 4,
},
focus && { border: '2px solid var(--primaryMain)', margin: -1 },
Expand Down
4 changes: 4 additions & 0 deletions src/theme/mui4Theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export function Mui4TableThemeProvider({
colors: {
primary: muiTheme.palette.primary,
secondary: muiTheme.palette.secondary,
background: muiTheme.palette.background.default,
text: muiTheme.palette.text.primary,
border: muiTheme.palette.divider,
borderLight: muiTheme.palette.divider,
},
},
mui4Theme,
Expand Down
4 changes: 4 additions & 0 deletions src/theme/mui5Theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export function Mui5TableThemeProvider({
colors: {
primary: muiTheme.palette.primary,
secondary: muiTheme.palette.secondary,
background: muiTheme.palette.background.default,
text: muiTheme.palette.text.primary,
border: muiTheme.palette.divider,
borderLight: muiTheme.palette.divider,
},
},
mui5Theme,
Expand Down
16 changes: 16 additions & 0 deletions src/theme/tableTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ export function mergeThemes<T>(...themes: PartialTableTheme<T>[]): PartialTableT
primary: Object.assign({}, ...themes.map((theme) => theme.colors?.primary)),
secondary: Object.assign({}, ...themes.map((theme) => theme.colors?.secondary)),
blocked: Object.assign({}, ...themes.map((theme) => theme.colors?.blocked)),
background: themes
.map((theme) => theme.colors?.background)
.reverse()
.find((x) => x !== undefined),
text: themes
.map((theme) => theme.colors?.text)
.reverse()
.find((x) => x !== undefined),
border: themes
.map((theme) => theme.colors?.border)
.reverse()
.find((x) => x !== undefined),
borderLight: themes
.map((theme) => theme.colors?.borderLight)
.reverse()
.find((x) => x !== undefined),
},
spacing: themes
.map((theme) => theme.spacing)
Expand Down
4 changes: 4 additions & 0 deletions src/theme/useCssVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function useCssVariables() {
'--blockedMain': colors.blocked.main,
'--blockedLight': colors.blocked.light,
'--blockedContrastText': colors.blocked.contrastText,
'--table-background-color': colors.background,
'--table-text-color': colors.text,
'--table-border-color': colors.border,
'--table-border-light-color': colors.borderLight,
};
});
}
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export interface TableTheme<T = unknown> {
primary: { main: string; light: string; contrastText: string };
secondary: { main: string; light: string; contrastText: string };
blocked: { main: string; light: string; contrastText: string };
background: string;
text: string;
border: string;
borderLight: string;
};
/** Spacing. */
spacing: string | number;
Expand Down

0 comments on commit b2b14de

Please sign in to comment.