@voiceflow/style 1.7.0 → 1.8.0
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.
- package/build/cjs/ThemeContext.d.ts +0 -1
- package/build/cjs/ThemeContext.d.ts.map +1 -1
- package/build/cjs/__fixtures__/Button/Button.component.d.ts +0 -1
- package/build/cjs/__fixtures__/Button/Button.component.d.ts.map +1 -1
- package/build/cjs/__fixtures__/Button/Button.styled.d.ts +0 -1
- package/build/cjs/__fixtures__/Button/Button.styled.d.ts.map +1 -1
- package/build/cjs/__fixtures__/Button/index.d.ts +0 -1
- package/build/cjs/__fixtures__/Button/index.d.ts.map +1 -1
- package/build/cjs/__fixtures__/InlineThemedButton/InlineThemedButton.component.d.ts +0 -1
- package/build/cjs/__fixtures__/InlineThemedButton/InlineThemedButton.component.d.ts.map +1 -1
- package/build/cjs/__fixtures__/InlineThemedButton/index.d.ts +0 -1
- package/build/cjs/__fixtures__/InlineThemedButton/index.d.ts.map +1 -1
- package/build/cjs/__fixtures__/InlineVarButton/InlineVarButton.component.d.ts +0 -1
- package/build/cjs/__fixtures__/InlineVarButton/InlineVarButton.component.d.ts.map +1 -1
- package/build/cjs/__fixtures__/InlineVarButton/index.d.ts +0 -1
- package/build/cjs/__fixtures__/InlineVarButton/index.d.ts.map +1 -1
- package/build/cjs/__fixtures__/RecipeButton/RecipeButton.component.d.ts +0 -1
- package/build/cjs/__fixtures__/RecipeButton/RecipeButton.component.d.ts.map +1 -1
- package/build/cjs/__fixtures__/RecipeButton/index.d.ts +0 -1
- package/build/cjs/__fixtures__/RecipeButton/index.d.ts.map +1 -1
- package/build/cjs/__fixtures__/ReuseCSS/ReuseCSS.component.d.ts +0 -1
- package/build/cjs/__fixtures__/ReuseCSS/ReuseCSS.component.d.ts.map +1 -1
- package/build/cjs/__fixtures__/ReuseCSS/index.d.ts +0 -1
- package/build/cjs/__fixtures__/ReuseCSS/index.d.ts.map +1 -1
- package/build/cjs/__fixtures__/ReuseStyled/ReuseStyled.component.d.ts +0 -1
- package/build/cjs/__fixtures__/ReuseStyled/ReuseStyled.component.d.ts.map +1 -1
- package/build/cjs/__fixtures__/ReuseStyled/ReuseStyled.styled.d.ts +0 -1
- package/build/cjs/__fixtures__/ReuseStyled/ReuseStyled.styled.d.ts.map +1 -1
- package/build/cjs/__fixtures__/ReuseStyled/index.d.ts +0 -1
- package/build/cjs/__fixtures__/ReuseStyled/index.d.ts.map +1 -1
- package/build/cjs/__fixtures__/ThemedButton/ThemedButton.component.d.ts +0 -1
- package/build/cjs/__fixtures__/ThemedButton/ThemedButton.component.d.ts.map +1 -1
- package/build/cjs/__fixtures__/ThemedButton/ThemedButton.styled.d.ts +0 -1
- package/build/cjs/__fixtures__/ThemedButton/ThemedButton.styled.d.ts.map +1 -1
- package/build/cjs/__fixtures__/ThemedButton/index.d.ts +0 -1
- package/build/cjs/__fixtures__/ThemedButton/index.d.ts.map +1 -1
- package/build/cjs/__fixtures__/VariantButton/VariantButton.component.d.ts +0 -1
- package/build/cjs/__fixtures__/VariantButton/VariantButton.component.d.ts.map +1 -1
- package/build/cjs/__fixtures__/VariantButton/index.d.ts +0 -1
- package/build/cjs/__fixtures__/VariantButton/index.d.ts.map +1 -1
- package/build/cjs/styled/factory.d.ts +2 -1
- package/build/cjs/styled/factory.d.ts.map +1 -1
- package/build/cjs/styled/types.d.ts +0 -1
- package/build/cjs/styled/types.d.ts.map +1 -1
- package/build/esm/ThemeContext.d.ts +0 -1
- package/build/esm/ThemeContext.d.ts.map +1 -1
- package/build/esm/__fixtures__/Button/Button.component.d.ts +0 -1
- package/build/esm/__fixtures__/Button/Button.component.d.ts.map +1 -1
- package/build/esm/__fixtures__/Button/Button.styled.d.ts +0 -1
- package/build/esm/__fixtures__/Button/Button.styled.d.ts.map +1 -1
- package/build/esm/__fixtures__/Button/index.d.ts +0 -1
- package/build/esm/__fixtures__/Button/index.d.ts.map +1 -1
- package/build/esm/__fixtures__/InlineThemedButton/InlineThemedButton.component.d.ts +0 -1
- package/build/esm/__fixtures__/InlineThemedButton/InlineThemedButton.component.d.ts.map +1 -1
- package/build/esm/__fixtures__/InlineThemedButton/index.d.ts +0 -1
- package/build/esm/__fixtures__/InlineThemedButton/index.d.ts.map +1 -1
- package/build/esm/__fixtures__/InlineVarButton/InlineVarButton.component.d.ts +0 -1
- package/build/esm/__fixtures__/InlineVarButton/InlineVarButton.component.d.ts.map +1 -1
- package/build/esm/__fixtures__/InlineVarButton/index.d.ts +0 -1
- package/build/esm/__fixtures__/InlineVarButton/index.d.ts.map +1 -1
- package/build/esm/__fixtures__/RecipeButton/RecipeButton.component.d.ts +0 -1
- package/build/esm/__fixtures__/RecipeButton/RecipeButton.component.d.ts.map +1 -1
- package/build/esm/__fixtures__/RecipeButton/index.d.ts +0 -1
- package/build/esm/__fixtures__/RecipeButton/index.d.ts.map +1 -1
- package/build/esm/__fixtures__/ReuseCSS/ReuseCSS.component.d.ts +0 -1
- package/build/esm/__fixtures__/ReuseCSS/ReuseCSS.component.d.ts.map +1 -1
- package/build/esm/__fixtures__/ReuseCSS/index.d.ts +0 -1
- package/build/esm/__fixtures__/ReuseCSS/index.d.ts.map +1 -1
- package/build/esm/__fixtures__/ReuseStyled/ReuseStyled.component.d.ts +0 -1
- package/build/esm/__fixtures__/ReuseStyled/ReuseStyled.component.d.ts.map +1 -1
- package/build/esm/__fixtures__/ReuseStyled/ReuseStyled.styled.d.ts +0 -1
- package/build/esm/__fixtures__/ReuseStyled/ReuseStyled.styled.d.ts.map +1 -1
- package/build/esm/__fixtures__/ReuseStyled/index.d.ts +0 -1
- package/build/esm/__fixtures__/ReuseStyled/index.d.ts.map +1 -1
- package/build/esm/__fixtures__/ThemedButton/ThemedButton.component.d.ts +0 -1
- package/build/esm/__fixtures__/ThemedButton/ThemedButton.component.d.ts.map +1 -1
- package/build/esm/__fixtures__/ThemedButton/ThemedButton.styled.d.ts +0 -1
- package/build/esm/__fixtures__/ThemedButton/ThemedButton.styled.d.ts.map +1 -1
- package/build/esm/__fixtures__/ThemedButton/index.d.ts +0 -1
- package/build/esm/__fixtures__/ThemedButton/index.d.ts.map +1 -1
- package/build/esm/__fixtures__/VariantButton/VariantButton.component.d.ts +0 -1
- package/build/esm/__fixtures__/VariantButton/VariantButton.component.d.ts.map +1 -1
- package/build/esm/__fixtures__/VariantButton/index.d.ts +0 -1
- package/build/esm/__fixtures__/VariantButton/index.d.ts.map +1 -1
- package/build/esm/styled/factory.d.ts +2 -1
- package/build/esm/styled/factory.d.ts.map +1 -1
- package/build/esm/styled/types.d.ts +0 -1
- package/build/esm/styled/types.d.ts.map +1 -1
- package/package.json +24 -31
- package/CHANGELOG.md +0 -105
- package/build/cjs/styled/factory.test.d.ts +0 -2
- package/build/cjs/styled/factory.test.d.ts.map +0 -1
- package/build/cjs/styled/factory.test.js +0 -140
- package/build/esm/styled/factory.test.d.ts +0 -2
- package/build/esm/styled/factory.test.d.ts.map +0 -1
- package/build/esm/styled/factory.test.js +0 -138
- package/config/test/setup.js +0 -9
- package/sonar-project.properties +0 -10
- package/src/ThemeContext.tsx +0 -14
- package/src/__fixtures__/Button/Button.component.tsx +0 -7
- package/src/__fixtures__/Button/Button.css.ts +0 -7
- package/src/__fixtures__/Button/Button.styled.ts +0 -5
- package/src/__fixtures__/Button/index.ts +0 -7
- package/src/__fixtures__/InlineThemedButton/InlineThemedButton.component.tsx +0 -13
- package/src/__fixtures__/InlineThemedButton/InlineThemedButton.css.ts +0 -8
- package/src/__fixtures__/InlineThemedButton/InlineThemedButton.styled.ts +0 -7
- package/src/__fixtures__/InlineThemedButton/index.ts +0 -4
- package/src/__fixtures__/InlineVarButton/InlineVarButton.component.tsx +0 -12
- package/src/__fixtures__/InlineVarButton/InlineVarButton.css.ts +0 -12
- package/src/__fixtures__/InlineVarButton/InlineVarButton.styled.ts +0 -10
- package/src/__fixtures__/InlineVarButton/index.ts +0 -4
- package/src/__fixtures__/RecipeButton/RecipeButton.component.tsx +0 -13
- package/src/__fixtures__/RecipeButton/RecipeButton.css.ts +0 -22
- package/src/__fixtures__/RecipeButton/RecipeButton.styled.ts +0 -6
- package/src/__fixtures__/RecipeButton/index.ts +0 -4
- package/src/__fixtures__/ReuseCSS/ReuseCSS.component.tsx +0 -8
- package/src/__fixtures__/ReuseCSS/ReuseCSS.css.ts +0 -11
- package/src/__fixtures__/ReuseCSS/index.ts +0 -4
- package/src/__fixtures__/ReuseStyled/ReuseStyled.component.tsx +0 -6
- package/src/__fixtures__/ReuseStyled/ReuseStyled.css.ts +0 -6
- package/src/__fixtures__/ReuseStyled/ReuseStyled.styled.ts +0 -6
- package/src/__fixtures__/ReuseStyled/index.ts +0 -4
- package/src/__fixtures__/ThemedButton/ThemedButton.component.tsx +0 -6
- package/src/__fixtures__/ThemedButton/ThemedButton.css.ts +0 -8
- package/src/__fixtures__/ThemedButton/ThemedButton.styled.ts +0 -6
- package/src/__fixtures__/ThemedButton/index.ts +0 -4
- package/src/__fixtures__/VariantButton/VariantButton.component.tsx +0 -13
- package/src/__fixtures__/VariantButton/VariantButton.css.ts +0 -6
- package/src/__fixtures__/VariantButton/VariantButton.styled.ts +0 -6
- package/src/__fixtures__/VariantButton/index.ts +0 -4
- package/src/__fixtures__/index.ts +0 -9
- package/src/__fixtures__/theme.css.ts +0 -21
- package/src/main.ts +0 -9
- package/src/styled/constants.ts +0 -1
- package/src/styled/factory.test.tsx +0 -181
- package/src/styled/factory.tsx +0 -39
- package/src/styled/index.ts +0 -4
- package/src/styled/types.ts +0 -87
- package/src/styled/utils.ts +0 -56
- package/src/testing.ts +0 -15
- package/src/types.ts +0 -10
- package/tsconfig.build.cjs.json +0 -8
- package/tsconfig.build.esm.json +0 -11
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -16
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { VariantProps } from '@/main';
|
|
2
|
-
|
|
3
|
-
import type { ButtonProps } from '../Button';
|
|
4
|
-
import type { complex } from './RecipeButton.css';
|
|
5
|
-
import * as S from './RecipeButton.styled';
|
|
6
|
-
|
|
7
|
-
export interface RecipeButtonProps extends ButtonProps, VariantProps<typeof complex> {}
|
|
8
|
-
|
|
9
|
-
export const RecipeButton: React.FC<RecipeButtonProps> = ({ color, fontSize, onClick, children }) => (
|
|
10
|
-
<S.Base variants={{ color, fontSize }} onClick={onClick}>
|
|
11
|
-
{children}
|
|
12
|
-
</S.Base>
|
|
13
|
-
);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { recipe } from '@/main';
|
|
2
|
-
|
|
3
|
-
export const complex = recipe({
|
|
4
|
-
base: {
|
|
5
|
-
border: '1px dashed black',
|
|
6
|
-
},
|
|
7
|
-
variants: {
|
|
8
|
-
color: {
|
|
9
|
-
ok: { backgroundColor: 'cyan' },
|
|
10
|
-
warn: { backgroundColor: 'orange' },
|
|
11
|
-
},
|
|
12
|
-
fontSize: {
|
|
13
|
-
sm: { fontSize: 10 },
|
|
14
|
-
md: { fontSize: 14 },
|
|
15
|
-
lg: { fontSize: 18 },
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
defaultVariants: {
|
|
20
|
-
fontSize: 'lg',
|
|
21
|
-
},
|
|
22
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ButtonProps } from '../Button';
|
|
2
|
-
import type { variants } from './VariantButton.css';
|
|
3
|
-
import * as S from './VariantButton.styled';
|
|
4
|
-
|
|
5
|
-
export interface VariantButtonProps extends ButtonProps {
|
|
6
|
-
variant: keyof typeof variants;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const VariantButton: React.FC<VariantButtonProps> = ({ variant, onClick, children }) => (
|
|
10
|
-
<S.Base variant={variant} onClick={onClick}>
|
|
11
|
-
{children}
|
|
12
|
-
</S.Base>
|
|
13
|
-
);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './Button';
|
|
2
|
-
export * from './InlineThemedButton';
|
|
3
|
-
export * from './InlineVarButton';
|
|
4
|
-
export * from './RecipeButton';
|
|
5
|
-
export * from './ReuseCSS';
|
|
6
|
-
export * from './ReuseStyled';
|
|
7
|
-
export * as Theme from './theme.css';
|
|
8
|
-
export * from './ThemedButton';
|
|
9
|
-
export * from './VariantButton';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createTheme } from '@/main';
|
|
2
|
-
|
|
3
|
-
export const spacing = {
|
|
4
|
-
sm: '2px',
|
|
5
|
-
md: '4px',
|
|
6
|
-
lg: '8px',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const [light, vars] = createTheme({
|
|
10
|
-
color: {
|
|
11
|
-
brand: 'red',
|
|
12
|
-
},
|
|
13
|
-
spacing,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const dark = createTheme(vars, {
|
|
17
|
-
color: {
|
|
18
|
-
brand: 'blue',
|
|
19
|
-
},
|
|
20
|
-
spacing,
|
|
21
|
-
});
|
package/src/main.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './styled';
|
|
2
|
-
export * from './testing';
|
|
3
|
-
export * from './ThemeContext';
|
|
4
|
-
export * from './types';
|
|
5
|
-
export * from '@vanilla-extract/css';
|
|
6
|
-
export * from '@vanilla-extract/dynamic';
|
|
7
|
-
export type { RuntimeFn } from '@vanilla-extract/recipes';
|
|
8
|
-
export { recipe } from '@vanilla-extract/recipes';
|
|
9
|
-
export { clsx } from 'clsx';
|
package/src/styled/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const STYLED_CLASS = Symbol('styled_class');
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
-
import { describe, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
Button,
|
|
6
|
-
InlineThemedButton,
|
|
7
|
-
InlineVarButton,
|
|
8
|
-
RecipeButton,
|
|
9
|
-
ReuseCSS,
|
|
10
|
-
ReuseStyled,
|
|
11
|
-
Theme,
|
|
12
|
-
ThemedButton,
|
|
13
|
-
VariantButton,
|
|
14
|
-
} from '@/__fixtures__';
|
|
15
|
-
import { ThemeProvider } from '@/ThemeContext';
|
|
16
|
-
|
|
17
|
-
const BASE_STYLE = {
|
|
18
|
-
padding: '20px',
|
|
19
|
-
borderRadius: '10px',
|
|
20
|
-
margin: '10px',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
describe('styled factory', () => {
|
|
24
|
-
describe('static styling', () => {
|
|
25
|
-
it('should inherit styles from static CSS', () => {
|
|
26
|
-
render(<Button />);
|
|
27
|
-
|
|
28
|
-
const el = screen.getByRole('button');
|
|
29
|
-
expect(el).toHaveClass(Button.css.base);
|
|
30
|
-
expect(el).toHaveStyle(BASE_STYLE);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('reusable CSS', () => {
|
|
35
|
-
it('should extend static CSS with overrides', () => {
|
|
36
|
-
render(<ReuseCSS />);
|
|
37
|
-
|
|
38
|
-
const el = screen.getByRole('button');
|
|
39
|
-
expect(el).toHaveClass(Button.css.base, ReuseCSS.css.base);
|
|
40
|
-
expect(el).toHaveStyle({
|
|
41
|
-
padding: '20px',
|
|
42
|
-
margin: '10px',
|
|
43
|
-
backgroundColor: 'red',
|
|
44
|
-
borderRadius: '0',
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('reusable styled components', () => {
|
|
50
|
-
it('should extend styled component with overrides', () => {
|
|
51
|
-
render(<ReuseStyled />);
|
|
52
|
-
|
|
53
|
-
const el = screen.getByRole('button');
|
|
54
|
-
expect(el).toHaveClass(Button.css.base, ReuseStyled.css.override);
|
|
55
|
-
expect(el).toHaveStyle({
|
|
56
|
-
padding: '20px',
|
|
57
|
-
border: '1px solid red',
|
|
58
|
-
margin: '2px',
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('style variants', () => {
|
|
64
|
-
it('should render the primary style variant', () => {
|
|
65
|
-
render(<VariantButton variant="primary" />);
|
|
66
|
-
|
|
67
|
-
const el = screen.getByRole('button');
|
|
68
|
-
expect(el).toHaveClass(Button.css.base, VariantButton.css.variants.primary);
|
|
69
|
-
expect(el).toHaveStyle({
|
|
70
|
-
...BASE_STYLE,
|
|
71
|
-
borderWidth: '2px',
|
|
72
|
-
borderColor: 'pink',
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should render the secondary style variant', () => {
|
|
77
|
-
render(<VariantButton variant="secondary" />);
|
|
78
|
-
|
|
79
|
-
const el = screen.getByRole('button');
|
|
80
|
-
expect(el).toHaveClass(Button.css.base, VariantButton.css.variants.secondary);
|
|
81
|
-
expect(el).toHaveStyle({
|
|
82
|
-
...BASE_STYLE,
|
|
83
|
-
borderWidth: '2px',
|
|
84
|
-
borderColor: 'blue',
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('style recipes', () => {
|
|
90
|
-
it('should render a recipe with default variants', () => {
|
|
91
|
-
render(<RecipeButton />);
|
|
92
|
-
|
|
93
|
-
const el = screen.getByRole('button');
|
|
94
|
-
expect(el).toHaveClass(Button.css.base);
|
|
95
|
-
expect(el).toHaveStyle({
|
|
96
|
-
...BASE_STYLE,
|
|
97
|
-
border: '1px dashed black',
|
|
98
|
-
fontSize: '18px',
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should render a recipe with selected variants', () => {
|
|
103
|
-
render(<RecipeButton fontSize="sm" color="warn" />);
|
|
104
|
-
|
|
105
|
-
const el = screen.getByRole('button');
|
|
106
|
-
expect(el).toHaveClass(Button.css.base);
|
|
107
|
-
expect(el).toHaveStyle({
|
|
108
|
-
...BASE_STYLE,
|
|
109
|
-
border: '1px dashed black',
|
|
110
|
-
backgroundColor: 'orange',
|
|
111
|
-
fontSize: '10px',
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// unable to test CSS variables fully in JSDOM it seems
|
|
117
|
-
// https://github.com/jsdom/jsdom/pull/3299
|
|
118
|
-
describe.skip('themed components', () => {
|
|
119
|
-
it('should render styles from the provided theme', () => {
|
|
120
|
-
render(
|
|
121
|
-
<ThemeProvider theme={Theme.light}>
|
|
122
|
-
<ThemedButton />
|
|
123
|
-
</ThemeProvider>
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const el = screen.getByRole('button');
|
|
127
|
-
expect(el).toHaveClass(Button.css.base, ThemedButton.css.themed);
|
|
128
|
-
expect(el).toHaveStyle({
|
|
129
|
-
...BASE_STYLE,
|
|
130
|
-
color: 'red',
|
|
131
|
-
borderRadius: '0',
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should override styles with contextual themes', () => {
|
|
136
|
-
render(
|
|
137
|
-
<ThemeProvider theme={Theme.light}>
|
|
138
|
-
<ThemeProvider theme={Theme.dark}>
|
|
139
|
-
<ThemedButton />
|
|
140
|
-
</ThemeProvider>
|
|
141
|
-
</ThemeProvider>
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const el = screen.getByRole('button');
|
|
145
|
-
expect(el).toHaveClass(Button.css.base, ThemedButton.css.themed);
|
|
146
|
-
expect(el).toHaveStyle({
|
|
147
|
-
...BASE_STYLE,
|
|
148
|
-
color: 'blue',
|
|
149
|
-
borderRadius: '0',
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe.skip('inline CSS variables', () => {
|
|
155
|
-
it('should render style from dynamic values', () => {
|
|
156
|
-
render(<InlineVarButton brandColor="green" />);
|
|
157
|
-
|
|
158
|
-
const el = screen.getByRole('button');
|
|
159
|
-
expect(el).toHaveClass(Button.css.base, InlineVarButton.css.base);
|
|
160
|
-
expect(el).toHaveStyle({
|
|
161
|
-
...BASE_STYLE,
|
|
162
|
-
color: 'green',
|
|
163
|
-
borderRadius: '0',
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe.skip('inline theme', () => {
|
|
169
|
-
it('should render style from inline theme', () => {
|
|
170
|
-
render(<InlineThemedButton brandColor="green" />);
|
|
171
|
-
|
|
172
|
-
const el = screen.getByRole('button');
|
|
173
|
-
expect(el).toHaveClass(Button.css.base, InlineThemedButton.css.themed);
|
|
174
|
-
expect(el).toHaveStyle({
|
|
175
|
-
...BASE_STYLE,
|
|
176
|
-
color: 'green',
|
|
177
|
-
borderRadius: '0',
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
});
|
package/src/styled/factory.tsx
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { clsx } from 'clsx';
|
|
2
|
-
import { createElement } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useTheme } from '../ThemeContext';
|
|
5
|
-
import { STYLED_CLASS } from './constants';
|
|
6
|
-
import type {
|
|
7
|
-
DynamicOptions,
|
|
8
|
-
FirstStyledArgument,
|
|
9
|
-
SecondStyledArgument,
|
|
10
|
-
StyledComponent,
|
|
11
|
-
StyledComponentProps,
|
|
12
|
-
StyledFactory,
|
|
13
|
-
} from './types';
|
|
14
|
-
import { getDynamicOptions, getStaticClass, useDynamicClass, useInlineStyle } from './utils';
|
|
15
|
-
|
|
16
|
-
export const styled = new Proxy<{
|
|
17
|
-
[Tag in keyof JSX.IntrinsicElements]: StyledFactory<Tag>;
|
|
18
|
-
}>({} as any, {
|
|
19
|
-
get:
|
|
20
|
-
<Tag extends keyof JSX.IntrinsicElements>(_target: unknown, tag: Tag): StyledFactory<Tag> =>
|
|
21
|
-
(firstArg: FirstStyledArgument, secondArg?: SecondStyledArgument, thirdArg?: DynamicOptions) => {
|
|
22
|
-
const staticClass = getStaticClass(firstArg, secondArg);
|
|
23
|
-
const dynamicOptions = getDynamicOptions(secondArg, thirdArg);
|
|
24
|
-
|
|
25
|
-
const StyledComponent = (props: StyledComponentProps<Tag, any, any, { variant?: any; variants?: any }>) => {
|
|
26
|
-
const themeClass = useTheme();
|
|
27
|
-
const dynamicClass = useDynamicClass(firstArg, props);
|
|
28
|
-
const inlineStyle = useInlineStyle(props, dynamicOptions);
|
|
29
|
-
|
|
30
|
-
return createElement(tag, {
|
|
31
|
-
...(props as React.ComponentPropsWithoutRef<Tag>),
|
|
32
|
-
className: clsx(themeClass, staticClass, dynamicClass, props.className),
|
|
33
|
-
style: { ...inlineStyle, ...props.style },
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return Object.assign(StyledComponent, { [STYLED_CLASS]: staticClass }) as StyledComponent<any>;
|
|
38
|
-
},
|
|
39
|
-
});
|
package/src/styled/index.ts
DELETED
package/src/styled/types.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
import type { assignInlineVars } from '@vanilla-extract/dynamic';
|
|
3
|
-
import type { RecipeVariants, RuntimeFn } from '@vanilla-extract/recipes';
|
|
4
|
-
|
|
5
|
-
import type { STYLED_CLASS } from './constants';
|
|
6
|
-
|
|
7
|
-
export type ThemeContract = Parameters<typeof assignInlineVars>[0];
|
|
8
|
-
|
|
9
|
-
export interface DynamicOptions<
|
|
10
|
-
Theme extends ThemeContract | null = ThemeContract,
|
|
11
|
-
Variables extends Record<string, string> | null = Record<string, string>
|
|
12
|
-
> {
|
|
13
|
-
/**
|
|
14
|
-
* the contract for a theme that can be overridden via a `theme` prop
|
|
15
|
-
*/
|
|
16
|
-
theme?: Theme;
|
|
17
|
-
/**
|
|
18
|
-
* variables that can be overridden via a `vars` prop
|
|
19
|
-
*/
|
|
20
|
-
vars?: Variables;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type DynamicThemeProps<Theme> = Theme extends ThemeContract
|
|
24
|
-
? {
|
|
25
|
-
/**
|
|
26
|
-
* inline override for the theme used to style this component
|
|
27
|
-
*/
|
|
28
|
-
theme?: Parameters<typeof assignInlineVars<Theme>>[1];
|
|
29
|
-
}
|
|
30
|
-
: {};
|
|
31
|
-
|
|
32
|
-
export type DynamicVariablesProps<Variables> = Variables extends Record<string, string>
|
|
33
|
-
? {
|
|
34
|
-
/**
|
|
35
|
-
* inline override for variables used to styled this component
|
|
36
|
-
*/
|
|
37
|
-
vars?: Partial<{ [K in keyof Variables]: string }>;
|
|
38
|
-
}
|
|
39
|
-
: {};
|
|
40
|
-
|
|
41
|
-
export type StyledComponentProps<
|
|
42
|
-
Tag extends keyof JSX.IntrinsicElements,
|
|
43
|
-
Theme,
|
|
44
|
-
Variables,
|
|
45
|
-
Extras extends object = {}
|
|
46
|
-
> = React.ComponentPropsWithoutRef<Tag> & DynamicThemeProps<Theme> & DynamicVariablesProps<Variables> & Extras;
|
|
47
|
-
|
|
48
|
-
export interface StyledComponent<Props = {}> extends React.FunctionComponent<Props> {
|
|
49
|
-
(props: Props, context?: any): React.ReactElement<any, any> | null;
|
|
50
|
-
[STYLED_CLASS]: string | null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type StyleSource = StyledComponent | string;
|
|
54
|
-
|
|
55
|
-
export interface StyledFactory<Tag extends keyof JSX.IntrinsicElements> {
|
|
56
|
-
<
|
|
57
|
-
Recipe extends RuntimeFn<Record<string, any>>,
|
|
58
|
-
Theme extends ThemeContract | null = null,
|
|
59
|
-
Variables extends Record<string, string> | null = null
|
|
60
|
-
>(
|
|
61
|
-
recipe: Recipe,
|
|
62
|
-
sources?: StyleSource[],
|
|
63
|
-
dynamic?: DynamicOptions<Theme, Variables>
|
|
64
|
-
): StyledComponent<StyledComponentProps<Tag, Theme, Variables, { variants: RecipeVariants<Recipe> }>>;
|
|
65
|
-
|
|
66
|
-
<
|
|
67
|
-
Variant extends string,
|
|
68
|
-
Theme extends ThemeContract | null = null,
|
|
69
|
-
Variables extends Record<string, string> | null = null
|
|
70
|
-
>(
|
|
71
|
-
variants: Record<Variant, string>,
|
|
72
|
-
sources?: StyleSource[],
|
|
73
|
-
dynamic?: DynamicOptions<Theme, Variables>
|
|
74
|
-
): StyledComponent<StyledComponentProps<Tag, Theme, Variables, { variant: Variant }>>;
|
|
75
|
-
|
|
76
|
-
<Theme extends ThemeContract | null = null, Variables extends Record<string, string> | null = null>(
|
|
77
|
-
sources: StyleSource[],
|
|
78
|
-
dynamic?: DynamicOptions<Theme, Variables>
|
|
79
|
-
): StyledComponent<StyledComponentProps<Tag, Theme, Variables>>;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type FirstStyledArgument<Variants extends {} = any> =
|
|
83
|
-
| RuntimeFn<Variants>
|
|
84
|
-
| Record<string, string>
|
|
85
|
-
| StyleSource[];
|
|
86
|
-
|
|
87
|
-
export type SecondStyledArgument = StyleSource[] | DynamicOptions;
|
package/src/styled/utils.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { assignInlineVars } from '@vanilla-extract/dynamic';
|
|
2
|
-
import { clsx } from 'clsx';
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
import { STYLED_CLASS } from './constants';
|
|
6
|
-
import type {
|
|
7
|
-
DynamicOptions,
|
|
8
|
-
FirstStyledArgument,
|
|
9
|
-
SecondStyledArgument,
|
|
10
|
-
StyledComponentProps,
|
|
11
|
-
ThemeContract,
|
|
12
|
-
} from './types';
|
|
13
|
-
|
|
14
|
-
export const getStaticClass = (firstArg: FirstStyledArgument, secondArg?: SecondStyledArgument): string | null => {
|
|
15
|
-
// eslint-disable-next-line no-nested-ternary
|
|
16
|
-
const classNames = (Array.isArray(firstArg) ? firstArg : Array.isArray(secondArg) ? secondArg : []).map((source) =>
|
|
17
|
-
typeof source === 'string' ? source : source[STYLED_CLASS]
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return classNames.length ? clsx(classNames) : null;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const getDynamicOptions = (secondArg?: SecondStyledArgument, thirdArg?: DynamicOptions): DynamicOptions | null =>
|
|
24
|
-
(Array.isArray(secondArg) ? thirdArg : secondArg) ?? null;
|
|
25
|
-
|
|
26
|
-
export const useDynamicClass = (
|
|
27
|
-
firstArg: FirstStyledArgument<any>,
|
|
28
|
-
props: { variant?: string; variants?: Record<string, any> }
|
|
29
|
-
) =>
|
|
30
|
-
useMemo(() => {
|
|
31
|
-
if (typeof firstArg === 'function') return firstArg(props.variants);
|
|
32
|
-
if (Array.isArray(firstArg) || !props.variant) return null;
|
|
33
|
-
|
|
34
|
-
return firstArg[props.variant];
|
|
35
|
-
}, [firstArg, props.variants, props.variant]);
|
|
36
|
-
|
|
37
|
-
export const useInlineStyle = (
|
|
38
|
-
props: StyledComponentProps<keyof JSX.IntrinsicElements, ThemeContract, Record<string, string>>,
|
|
39
|
-
dynamicOptions: DynamicOptions | null
|
|
40
|
-
) => {
|
|
41
|
-
const { theme, vars } = dynamicOptions ?? {};
|
|
42
|
-
|
|
43
|
-
return useMemo(() => {
|
|
44
|
-
const style = {};
|
|
45
|
-
|
|
46
|
-
if (theme && props.theme) {
|
|
47
|
-
Object.assign(style, assignInlineVars(theme, props.theme));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (vars && props.vars) {
|
|
51
|
-
Object.assign(style, assignInlineVars(props.vars as Record<string, string>));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return style;
|
|
55
|
-
}, [props.theme, props.vars]);
|
|
56
|
-
};
|
package/src/testing.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* the pattern for data-testid attributes is based off of BEM naming
|
|
3
|
-
* https://getbem.com/naming/
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export const tid = (block: string | undefined, elements: string | [string, string, ...string[]], modifier?: string) => {
|
|
7
|
-
if (!block) return undefined;
|
|
8
|
-
|
|
9
|
-
const elementList = typeof elements === 'string' ? [elements] : elements;
|
|
10
|
-
const blockElement = [block, ...elementList].join('__');
|
|
11
|
-
|
|
12
|
-
if (!modifier) return blockElement;
|
|
13
|
-
|
|
14
|
-
return `${blockElement}--${modifier}`;
|
|
15
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ComplexStyleRule } from '@vanilla-extract/css';
|
|
2
|
-
import type { RecipeVariants, RuntimeFn } from '@vanilla-extract/recipes';
|
|
3
|
-
import type { Simplify } from 'type-fest';
|
|
4
|
-
|
|
5
|
-
export type VariantStyleRules = Record<string, Record<string, ComplexStyleRule | string>>;
|
|
6
|
-
|
|
7
|
-
export type VariantProps<RecipeFn extends RuntimeFn<VariantStyleRules>> = Exclude<
|
|
8
|
-
Simplify<RecipeVariants<RecipeFn>>,
|
|
9
|
-
undefined | null
|
|
10
|
-
>;
|
package/tsconfig.build.cjs.json
DELETED
package/tsconfig.build.esm.json
DELETED