@basic-ui/material 1.0.0-alpha.34 → 1.0.0-alpha.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/build/cjs/index.js +3 -3
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/esm/Alert/Alert.d.ts +1 -1
  4. package/build/esm/AppBar/AppBar.d.ts +1 -1
  5. package/build/esm/AppBar/AppBarButton.d.ts +1 -1
  6. package/build/esm/Badge/Badge.d.ts +1 -1
  7. package/build/esm/BottomSheet/BottomSheet.d.ts +1 -1
  8. package/build/esm/BottomSheet/BottomSheetSurface.d.ts +1 -1
  9. package/build/esm/Button/BaseButton.d.ts +1 -1
  10. package/build/esm/Button/Button.d.ts +1 -1
  11. package/build/esm/Button/ButtonGroup.d.ts +1 -1
  12. package/build/esm/Button/FilledButton.d.ts +1 -1
  13. package/build/esm/Button/OutlinedButton.d.ts +1 -1
  14. package/build/esm/Button/TransparentButton.d.ts +1 -1
  15. package/build/esm/CheckBox/CheckBox.d.ts +1 -1
  16. package/build/esm/CheckBox/CheckBoxIcon.d.ts +1 -1
  17. package/build/esm/Chip/ButtonChip.d.ts +1 -1
  18. package/build/esm/Chip/ChipBase.d.ts +1 -1
  19. package/build/esm/Chip/ChoiceChip.d.ts +1 -1
  20. package/build/esm/Combobox/Combobox.d.ts +7 -7
  21. package/build/esm/Dialog/Dialog.d.ts +1 -1
  22. package/build/esm/Dialog/DialogBackdrop.d.ts +1 -1
  23. package/build/esm/Dialog/DialogSurface.d.ts +1 -1
  24. package/build/esm/Divider/Divider.d.ts +1 -1
  25. package/build/esm/LineRipple/LineRipple.d.ts +1 -1
  26. package/build/esm/Link/Link.d.ts +1 -1
  27. package/build/esm/List/List.d.ts +1 -1
  28. package/build/esm/ListItem/ListItem.d.ts +1 -1
  29. package/build/esm/Menu/Menu.d.ts +5 -5
  30. package/build/esm/NavRail/NavRailItem.d.ts +3 -3
  31. package/build/esm/Paper/Paper.d.ts +1 -1
  32. package/build/esm/RadioButton/RadioGroup.d.ts +1 -1
  33. package/build/esm/Select/CustomContainerExample.d.ts +1 -1
  34. package/build/esm/Select/Select.d.ts +3 -3
  35. package/build/esm/Select/Select.js.map +1 -1
  36. package/build/esm/Select/SelectIcon.d.ts +1 -1
  37. package/build/esm/SelectionControl/SelectionControlLabel.d.ts +1 -1
  38. package/build/esm/SelectionControl/SelectionControlText.d.ts +1 -1
  39. package/build/esm/Skeleton/DelayAppearance.d.ts +1 -1
  40. package/build/esm/Skeleton/Skeleton.d.ts +1 -1
  41. package/build/esm/Slider/Slider.d.ts +6 -6
  42. package/build/esm/Snackbar/Snackbar.d.ts +1 -1
  43. package/build/esm/Switch/Switch.d.ts +1 -1
  44. package/build/esm/Tab/Tab.d.ts +1 -1
  45. package/build/esm/Tab/TabList.d.ts +1 -1
  46. package/build/esm/Tab/TabPanel.d.ts +1 -1
  47. package/build/esm/TabIndicator/TabIndicator.d.ts +1 -1
  48. package/build/esm/Table/Table.d.ts +1 -1
  49. package/build/esm/Table/TableHead.d.ts +1 -1
  50. package/build/esm/Table/TableRow.d.ts +1 -1
  51. package/build/esm/Text/Text.d.ts +1 -1
  52. package/build/esm/TextField/FilledContainer.d.ts +1 -1
  53. package/build/esm/TextField/HelperText.d.ts +1 -1
  54. package/build/esm/TextField/Input.d.ts +1 -1
  55. package/build/esm/TextField/OutlinedContainer.d.ts +1 -1
  56. package/build/esm/TextField/TextField.d.ts +1 -1
  57. package/build/esm/ThemeExplorer/ThemeBuilder.js +7 -0
  58. package/build/esm/ThemeExplorer/ThemeBuilder.js.map +1 -1
  59. package/build/esm/ThemeExplorer/makeTailwindTheme.d.ts +2 -0
  60. package/build/esm/ThemeExplorer/makeTailwindTheme.js +30 -0
  61. package/build/esm/ThemeExplorer/makeTailwindTheme.js.map +1 -0
  62. package/build/esm/Tooltip/Tooltip.d.ts +1 -1
  63. package/build/esm/tailwind/extendColors.d.ts +5 -0
  64. package/build/esm/tailwind/extendColors.js +59 -0
  65. package/build/esm/tailwind/extendColors.js.map +1 -0
  66. package/build/esm/tailwind/index.d.ts +8 -0
  67. package/build/esm/tailwind/index.js +45 -0
  68. package/build/esm/tailwind/index.js.map +1 -0
  69. package/build/esm/tailwind/makeTailwindTheme.d.ts +5 -0
  70. package/build/esm/tailwind/makeTailwindTheme.js +32 -0
  71. package/build/esm/tailwind/makeTailwindTheme.js.map +1 -0
  72. package/build/esm/theme/theme.js +3 -3
  73. package/build/esm/theme/theme.js.map +1 -1
  74. package/build/tsconfig-build.tsbuildinfo +1 -1
  75. package/package.json +16 -8
  76. package/src/Button/Button.story.tsx +4 -0
  77. package/src/Select/Select.tsx +2 -2
  78. package/src/ThemeExplorer/ThemeBuilder.tsx +6 -1
  79. package/src/ThemeExplorer/makeTailwindTheme.ts +44 -0
  80. package/src/tailwind/extendColors.ts +51 -0
  81. package/src/tailwind/index.ts +56 -0
  82. package/src/tailwind/tests/extendColors.test.ts +123 -0
  83. package/src/theme/theme.ts +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basic-ui/material",
3
- "version": "1.0.0-alpha.34",
3
+ "version": "1.0.0-alpha.36",
4
4
  "description": "Accessible React Components used as building blocks for UI patterns",
5
5
  "author": "Lucas Terra <lucasterra7@gmail.com>",
6
6
  "license": "MIT",
@@ -18,17 +18,18 @@
18
18
  "build:dts": "run -T tsc -p ./tsconfig-build.json --isolatedModules false --declaration --emitDeclarationOnly",
19
19
  "build:cjs": "run -T cross-env NODE_ENV=production rollup -c ../../rollup.config.js",
20
20
  "build:esm": "run -T cross-env NODE_ENV=production BABEL_ENV=esm run -T babel --config-file ../../babel.config.js ./src --extensions \".ts,.tsx,.js,.jsx\" --source-maps --out-dir ./build/esm --ignore \"**/*.story.tsx,**/*.story.ts,**/*.test.tsx,**/*.test.ts\"",
21
- "build-storybook": "run -T build-storybook -c ./scripts/storybook -o .out",
21
+ "build-storybook": "run -T sb build -c ./scripts/storybook -o .out",
22
22
  "lint": "run -T eslint 'src/**/*.{js,jsx,ts,tsx}' --fix",
23
23
  "format": "run -T prettier --write '**/*.js'",
24
- "start": "run -T start-storybook -p 9001 -c ./scripts/storybook",
24
+ "start": "run -T sb dev -p 9001 -c ./scripts/storybook",
25
25
  "serve": "run -T http-server .out",
26
26
  "typecheck": "run -T tsc --noEmit -p ./tsconfig.json",
27
- "test": "echo \"Error: no test specified\" && exit 1"
27
+ "test": "run -T jest --config ../../jest.config.js",
28
+ "test:watch": "yarn test --watch"
28
29
  },
29
30
  "dependencies": {
30
31
  "@basic-ui/core": "^0.0.51",
31
- "@basic-ui/dynamic-theme": "^0.0.8",
32
+ "@basic-ui/dynamic-theme": "^0.0.9",
32
33
  "@styled-system/should-forward-prop": "5.1.5",
33
34
  "@types/styled-system": "^5.1.10",
34
35
  "@types/styled-system__css": "^5.0.14",
@@ -40,7 +41,11 @@
40
41
  "@emotion/react": "11.9.0",
41
42
  "@emotion/styled": "11.8.1",
42
43
  "@material/material-color-utilities": "0.1.1",
43
- "polished": "^4.2.2"
44
+ "autoprefixer": "^10.4.14",
45
+ "polished": "^4.2.2",
46
+ "postcss": "^8.4.27",
47
+ "postcss-import": "^15.1.0",
48
+ "tailwindcss": "^3.3.3"
44
49
  },
45
50
  "peerDependencies": {
46
51
  "@babel/runtime": "^7.0.0",
@@ -48,9 +53,12 @@
48
53
  "@emotion/react": "11.x",
49
54
  "@emotion/styled": "11.x",
50
55
  "@styled-system/css": "*",
56
+ "autoprefixer": "^10.0.0",
51
57
  "polished": ">=3.0.0",
58
+ "postcss": "^8.0.0",
52
59
  "react": "^16.14.0 || ^17.0.0 || ^18.0.0",
53
- "react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0"
60
+ "react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0",
61
+ "tailwindcss": "^3.0.0"
54
62
  },
55
- "gitHead": "5442c3e57c390b7f69adab60118d7d6df9f55df0"
63
+ "gitHead": "befcd640cc8951f08635b5e71b80cacfdc302339"
56
64
  }
@@ -29,6 +29,10 @@ const NavigationIcon = (props) => (
29
29
  const Example = (props) => {
30
30
  return (
31
31
  <Box bg="surface">
32
+ <div className="bg-primary w-16 h-16 text-body-medium">Hello</div>
33
+ <div className="bg-primary-container w-16 h-16" />
34
+ <div className="bg-on-primary-container w-16 h-16" />
35
+ <div className="bg-ss-container-high w-16 h-16" />
32
36
  <Box p={3} display="flex" sx={{ gap: 2 }}>
33
37
  <Button variant="filled" {...props}>
34
38
  Filled
@@ -61,7 +61,7 @@ export type SelectProps<ValueType extends string> = BaseSelectProps &
61
61
  e: ChangeEvent<HTMLSelectElement>,
62
62
  value: ValueType
63
63
  ) => void;
64
- renderValue?: (value?: ValueType | '') => ReactNode | undefined;
64
+ renderValue?: (value?: ValueType | '') => ReactNode;
65
65
  }
66
66
  | {
67
67
  multiple: true;
@@ -71,7 +71,7 @@ export type SelectProps<ValueType extends string> = BaseSelectProps &
71
71
  e: ChangeEvent<HTMLSelectElement>,
72
72
  value: ValueType[]
73
73
  ) => void;
74
- renderValue?: (value?: ValueType[]) => ReactNode[];
74
+ renderValue?: (value?: ValueType[]) => ReactNode;
75
75
  }
76
76
  );
77
77
 
@@ -28,6 +28,7 @@ import { FontAutoComplete, parseMainFont } from './FontAutoComplete';
28
28
  import type { Theme } from '../theme/theme';
29
29
  import { BorderSlider } from './BorderSlider';
30
30
  import { ColorSchemePicker } from './ColorSchemePicker';
31
+ import { makeTailwindThemeCSS } from './makeTailwindTheme';
31
32
 
32
33
  export interface ThemeBuilderProps {
33
34
  CodeHighlightingComponent?: ComponentType<{
@@ -338,11 +339,15 @@ const ThemeBuilderImpl = (props: ThemeBuilderProps) => {
338
339
  <TonalColors palette={n2} />
339
340
  </Box>
340
341
  </Box>
341
- {/* Color pickers */}
342
+ {/* Code pickers */}
342
343
  <Text variant="headline-small">Theme</Text>
343
344
  <CodeHighlightingComponent className={`language-json`}>
344
345
  {JSON.stringify(newTheme, null, 2)}
345
346
  </CodeHighlightingComponent>
347
+ <Text variant="headline-small">Tailwind Theme</Text>
348
+ <CodeHighlightingComponent className={`language-css`}>
349
+ {makeTailwindThemeCSS(newTheme as any)}
350
+ </CodeHighlightingComponent>
346
351
  </>
347
352
  );
348
353
  };
@@ -0,0 +1,44 @@
1
+ import {
2
+ DARK_SCHEME_CLASS,
3
+ LIGHT_SCHEME_CLASS,
4
+ transformTheme,
5
+ } from '@basic-ui/dynamic-theme';
6
+
7
+ import type { Theme } from '../theme/theme';
8
+
9
+ export function makeTailwindThemeCSS(theme: Theme) {
10
+ const transformedTheme = transformTheme(theme, []);
11
+ const { light, dark } = transformedTheme.colorModes;
12
+
13
+ const parseColorMode = (colors: Record<string, string>) => {
14
+ const keys = Object.keys(colors);
15
+ const cssLines: string[] = [];
16
+ // let css = '';
17
+ for (const key of keys) {
18
+ if (!key.endsWith('--rgb')) {
19
+ continue;
20
+ }
21
+
22
+ cssLines.push(` ` + key + ': ' + colors[key]);
23
+ }
24
+ return cssLines.join(';\n') + ';';
25
+ };
26
+
27
+ const bodySelector = `body`;
28
+ const lightThemeSelector = [
29
+ '' + bodySelector,
30
+ '' + bodySelector + '.' + LIGHT_SCHEME_CLASS,
31
+ '' + bodySelector + ' .' + LIGHT_SCHEME_CLASS,
32
+ ].join(',\n');
33
+ const darkThemeSelector = [
34
+ '' + bodySelector + '.' + DARK_SCHEME_CLASS,
35
+ '' + bodySelector + ' .' + DARK_SCHEME_CLASS,
36
+ ].join(',\n');
37
+
38
+ return `${lightThemeSelector} {
39
+ ${parseColorMode(light)}
40
+ }
41
+ ${darkThemeSelector} {
42
+ ${parseColorMode(dark)}
43
+ }`;
44
+ }
@@ -0,0 +1,51 @@
1
+ import type { Theme } from '../theme/theme';
2
+
3
+ export type ColorsObject = { [key: string]: string | ColorsObject };
4
+ export function extendColors(theme: Theme): ColorsObject {
5
+ const modifiedColors: ColorsObject = {};
6
+ function extractColors(colors: ColorsObject, arr: ColorsObject, root = '') {
7
+ function insert(key: string, value: string) {
8
+ const parts = key.split('-');
9
+
10
+ let obj: any = arr;
11
+ for (let i = 0; i < parts.length; i++) {
12
+ const part = parts[i];
13
+ const isLast = i === parts.length - 1;
14
+
15
+ if (isLast) {
16
+ if (typeof obj[part] === 'object') {
17
+ obj[part].DEFAULT = value;
18
+ } else {
19
+ obj[part] = value;
20
+ }
21
+ } else {
22
+ if (typeof obj[part] === 'string') {
23
+ obj[part] = { DEFAULT: obj[part] };
24
+ } else if (typeof obj[part] === 'undefined') {
25
+ obj[part] = {};
26
+ }
27
+ obj = obj[part];
28
+ }
29
+ }
30
+ }
31
+
32
+ for (const key of Object.keys(colors)) {
33
+ if (key === 'modes') {
34
+ continue;
35
+ }
36
+
37
+ const c = colors[key];
38
+ if (typeof c === 'string') {
39
+ const varName = `--${root + key}--rgb`;
40
+ insert(key, `rgba(var(${varName}), <alpha-value>)`);
41
+ } else if (typeof c === 'object') {
42
+ const subColors: ColorsObject = {};
43
+ extractColors(c, subColors, root + key + '-');
44
+ arr[key] = subColors;
45
+ }
46
+ }
47
+ }
48
+
49
+ extractColors(theme.colors as any, modifiedColors);
50
+ return modifiedColors;
51
+ }
@@ -0,0 +1,56 @@
1
+ import plugin from 'tailwindcss/plugin';
2
+ import type { Config as TailwindConfig } from 'tailwindcss';
3
+ import { css } from '@styled-system/css';
4
+
5
+ import type { Theme } from '../theme';
6
+ import { extendColors } from './extendColors';
7
+
8
+ export type PluginOptions = {
9
+ theme?: Theme;
10
+ };
11
+
12
+ const textVariants = [
13
+ 'display-large',
14
+ 'display-medium',
15
+ 'display-small',
16
+ 'headline-large',
17
+ 'headline-medium',
18
+ 'headline-small',
19
+ 'title-large',
20
+ 'title-medium',
21
+ 'title-small',
22
+ 'label-large',
23
+ 'label-medium',
24
+ 'label-small',
25
+ 'body-large',
26
+ 'body-medium',
27
+ 'body-small',
28
+ ];
29
+
30
+ export default function generatePreset({
31
+ theme: basicUiTheme,
32
+ }: {
33
+ theme: Theme;
34
+ }): TailwindConfig {
35
+ return {
36
+ content: [],
37
+ darkMode: 'class',
38
+ theme: {
39
+ colors: {
40
+ ...extendColors(basicUiTheme),
41
+ },
42
+ },
43
+ plugins: [
44
+ plugin(function ({ addComponents }) {
45
+ for (const variant of textVariants) {
46
+ const themeStyle = basicUiTheme.text[variant];
47
+ if (themeStyle) {
48
+ addComponents({
49
+ [`.text-${variant}`]: css(themeStyle)(basicUiTheme) as any,
50
+ });
51
+ }
52
+ }
53
+ }),
54
+ ],
55
+ };
56
+ }
@@ -0,0 +1,123 @@
1
+ import { extendColors } from '../extendColors';
2
+
3
+ test('extendColors', () => {
4
+ expect(
5
+ extendColors({
6
+ colors: {
7
+ primary: '#123456',
8
+ 'primary-container': '#123456',
9
+ secondary: '#123456',
10
+ surface: '#123456',
11
+ 'surface-container-lowest': '#123456',
12
+ 'surface-container-low': '#123456',
13
+ 'surface-container': '#123456',
14
+ 'surface-container-high': '#123456',
15
+ 'surface-container-highest': '#123456',
16
+ on: {
17
+ primary: '#123456',
18
+ 'primary-container': '#123456',
19
+ surface: '#123456',
20
+ 'surface-container-lowest': '#123456',
21
+ 'surface-container-low': '#123456',
22
+ 'surface-container': '#123456',
23
+ 'surface-container-high': '#123456',
24
+ 'surface-container-highest': '#123456',
25
+ },
26
+ },
27
+ } as any)
28
+ ).toMatchInlineSnapshot(`
29
+ Object {
30
+ "on": Object {
31
+ "primary": Object {
32
+ "DEFAULT": "rgba(var(--on-primary--rgb), <alpha-value>)",
33
+ "container": "rgba(var(--on-primary-container--rgb), <alpha-value>)",
34
+ },
35
+ "surface": Object {
36
+ "DEFAULT": "rgba(var(--on-surface--rgb), <alpha-value>)",
37
+ "container": Object {
38
+ "DEFAULT": "rgba(var(--on-surface-container--rgb), <alpha-value>)",
39
+ "high": "rgba(var(--on-surface-container-high--rgb), <alpha-value>)",
40
+ "highest": "rgba(var(--on-surface-container-highest--rgb), <alpha-value>)",
41
+ "low": "rgba(var(--on-surface-container-low--rgb), <alpha-value>)",
42
+ "lowest": "rgba(var(--on-surface-container-lowest--rgb), <alpha-value>)",
43
+ },
44
+ },
45
+ },
46
+ "primary": Object {
47
+ "DEFAULT": "rgba(var(--primary--rgb), <alpha-value>)",
48
+ "container": "rgba(var(--primary-container--rgb), <alpha-value>)",
49
+ },
50
+ "secondary": "rgba(var(--secondary--rgb), <alpha-value>)",
51
+ "surface": Object {
52
+ "DEFAULT": "rgba(var(--surface--rgb), <alpha-value>)",
53
+ "container": Object {
54
+ "DEFAULT": "rgba(var(--surface-container--rgb), <alpha-value>)",
55
+ "high": "rgba(var(--surface-container-high--rgb), <alpha-value>)",
56
+ "highest": "rgba(var(--surface-container-highest--rgb), <alpha-value>)",
57
+ "low": "rgba(var(--surface-container-low--rgb), <alpha-value>)",
58
+ "lowest": "rgba(var(--surface-container-lowest--rgb), <alpha-value>)",
59
+ },
60
+ },
61
+ }
62
+ `);
63
+
64
+ expect(
65
+ extendColors({
66
+ colors: {
67
+ primary: '#123456',
68
+ 'primary-container': '#123456',
69
+ secondary: '#123456',
70
+ 'surface-container-lowest': '#123456',
71
+ 'surface-container-low': '#123456',
72
+ 'surface-container-high': '#123456',
73
+ 'surface-container-highest': '#123456',
74
+ 'surface-container': '#123456',
75
+ surface: '#123456',
76
+ on: {
77
+ primary: '#123456',
78
+ 'primary-container': '#123456',
79
+ surface: '#123456',
80
+ 'surface-container-lowest': '#123456',
81
+ 'surface-container-low': '#123456',
82
+ 'surface-container': '#123456',
83
+ 'surface-container-high': '#123456',
84
+ 'surface-container-highest': '#123456',
85
+ },
86
+ },
87
+ } as any)
88
+ ).toMatchInlineSnapshot(`
89
+ Object {
90
+ "on": Object {
91
+ "primary": Object {
92
+ "DEFAULT": "rgba(var(--on-primary--rgb), <alpha-value>)",
93
+ "container": "rgba(var(--on-primary-container--rgb), <alpha-value>)",
94
+ },
95
+ "surface": Object {
96
+ "DEFAULT": "rgba(var(--on-surface--rgb), <alpha-value>)",
97
+ "container": Object {
98
+ "DEFAULT": "rgba(var(--on-surface-container--rgb), <alpha-value>)",
99
+ "high": "rgba(var(--on-surface-container-high--rgb), <alpha-value>)",
100
+ "highest": "rgba(var(--on-surface-container-highest--rgb), <alpha-value>)",
101
+ "low": "rgba(var(--on-surface-container-low--rgb), <alpha-value>)",
102
+ "lowest": "rgba(var(--on-surface-container-lowest--rgb), <alpha-value>)",
103
+ },
104
+ },
105
+ },
106
+ "primary": Object {
107
+ "DEFAULT": "rgba(var(--primary--rgb), <alpha-value>)",
108
+ "container": "rgba(var(--primary-container--rgb), <alpha-value>)",
109
+ },
110
+ "secondary": "rgba(var(--secondary--rgb), <alpha-value>)",
111
+ "surface": Object {
112
+ "DEFAULT": "rgba(var(--surface--rgb), <alpha-value>)",
113
+ "container": Object {
114
+ "DEFAULT": "rgba(var(--surface-container--rgb), <alpha-value>)",
115
+ "high": "rgba(var(--surface-container-high--rgb), <alpha-value>)",
116
+ "highest": "rgba(var(--surface-container-highest--rgb), <alpha-value>)",
117
+ "low": "rgba(var(--surface-container-low--rgb), <alpha-value>)",
118
+ "lowest": "rgba(var(--surface-container-lowest--rgb), <alpha-value>)",
119
+ },
120
+ },
121
+ }
122
+ `);
123
+ });
@@ -169,7 +169,7 @@ export const theme = {
169
169
  fontFamily: 'body',
170
170
  lineHeight: 'body',
171
171
  },
172
- 'display-large': font('brand', 64, 57, 0, 400),
172
+ 'display-large': font('brand', 64, 57, -0.25, 400),
173
173
  'display-medium': font('brand', 52, 45, 0, 400),
174
174
  'display-small': font('brand', 44, 36, 0, 400),
175
175
  'headline-large': font('brand', 40, 32, 0, 400),
@@ -486,8 +486,8 @@ export const theme = {
486
486
  styles: {
487
487
  root: {
488
488
  body: {
489
- fontFamily: 'body1',
490
- fontWeight: 'body1',
489
+ fontFamily: 'plain',
490
+ fontWeight: 'regular',
491
491
  lineHeight: 'body',
492
492
  backgroundColor: 'surface',
493
493
  color: 'on.surface',