@voiceflow/style 1.6.1 → 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.
Files changed (157) hide show
  1. package/build/cjs/ThemeContext.d.ts +0 -1
  2. package/build/cjs/ThemeContext.d.ts.map +1 -1
  3. package/build/cjs/__fixtures__/Button/Button.component.d.ts +0 -1
  4. package/build/cjs/__fixtures__/Button/Button.component.d.ts.map +1 -1
  5. package/build/cjs/__fixtures__/Button/Button.styled.d.ts +0 -1
  6. package/build/cjs/__fixtures__/Button/Button.styled.d.ts.map +1 -1
  7. package/build/cjs/__fixtures__/Button/index.d.ts +0 -1
  8. package/build/cjs/__fixtures__/Button/index.d.ts.map +1 -1
  9. package/build/cjs/__fixtures__/InlineThemedButton/InlineThemedButton.component.d.ts +0 -1
  10. package/build/cjs/__fixtures__/InlineThemedButton/InlineThemedButton.component.d.ts.map +1 -1
  11. package/build/cjs/__fixtures__/InlineThemedButton/index.d.ts +0 -1
  12. package/build/cjs/__fixtures__/InlineThemedButton/index.d.ts.map +1 -1
  13. package/build/cjs/__fixtures__/InlineVarButton/InlineVarButton.component.d.ts +0 -1
  14. package/build/cjs/__fixtures__/InlineVarButton/InlineVarButton.component.d.ts.map +1 -1
  15. package/build/cjs/__fixtures__/InlineVarButton/index.d.ts +0 -1
  16. package/build/cjs/__fixtures__/InlineVarButton/index.d.ts.map +1 -1
  17. package/build/cjs/__fixtures__/RecipeButton/RecipeButton.component.d.ts +0 -1
  18. package/build/cjs/__fixtures__/RecipeButton/RecipeButton.component.d.ts.map +1 -1
  19. package/build/cjs/__fixtures__/RecipeButton/index.d.ts +0 -1
  20. package/build/cjs/__fixtures__/RecipeButton/index.d.ts.map +1 -1
  21. package/build/cjs/__fixtures__/ReuseCSS/ReuseCSS.component.d.ts +0 -1
  22. package/build/cjs/__fixtures__/ReuseCSS/ReuseCSS.component.d.ts.map +1 -1
  23. package/build/cjs/__fixtures__/ReuseCSS/index.d.ts +0 -1
  24. package/build/cjs/__fixtures__/ReuseCSS/index.d.ts.map +1 -1
  25. package/build/cjs/__fixtures__/ReuseStyled/ReuseStyled.component.d.ts +0 -1
  26. package/build/cjs/__fixtures__/ReuseStyled/ReuseStyled.component.d.ts.map +1 -1
  27. package/build/cjs/__fixtures__/ReuseStyled/ReuseStyled.styled.d.ts +0 -1
  28. package/build/cjs/__fixtures__/ReuseStyled/ReuseStyled.styled.d.ts.map +1 -1
  29. package/build/cjs/__fixtures__/ReuseStyled/index.d.ts +0 -1
  30. package/build/cjs/__fixtures__/ReuseStyled/index.d.ts.map +1 -1
  31. package/build/cjs/__fixtures__/ThemedButton/ThemedButton.component.d.ts +0 -1
  32. package/build/cjs/__fixtures__/ThemedButton/ThemedButton.component.d.ts.map +1 -1
  33. package/build/cjs/__fixtures__/ThemedButton/ThemedButton.styled.d.ts +0 -1
  34. package/build/cjs/__fixtures__/ThemedButton/ThemedButton.styled.d.ts.map +1 -1
  35. package/build/cjs/__fixtures__/ThemedButton/index.d.ts +0 -1
  36. package/build/cjs/__fixtures__/ThemedButton/index.d.ts.map +1 -1
  37. package/build/cjs/__fixtures__/VariantButton/VariantButton.component.d.ts +0 -1
  38. package/build/cjs/__fixtures__/VariantButton/VariantButton.component.d.ts.map +1 -1
  39. package/build/cjs/__fixtures__/VariantButton/index.d.ts +0 -1
  40. package/build/cjs/__fixtures__/VariantButton/index.d.ts.map +1 -1
  41. package/build/cjs/main.d.ts +1 -0
  42. package/build/cjs/main.d.ts.map +1 -1
  43. package/build/cjs/main.js +1 -0
  44. package/build/cjs/styled/factory.d.ts +2 -1
  45. package/build/cjs/styled/factory.d.ts.map +1 -1
  46. package/build/cjs/styled/types.d.ts +0 -1
  47. package/build/cjs/styled/types.d.ts.map +1 -1
  48. package/build/cjs/testing.d.ts +6 -0
  49. package/build/cjs/testing.d.ts.map +1 -0
  50. package/build/cjs/testing.js +17 -0
  51. package/build/esm/ThemeContext.d.ts +0 -1
  52. package/build/esm/ThemeContext.d.ts.map +1 -1
  53. package/build/esm/__fixtures__/Button/Button.component.d.ts +0 -1
  54. package/build/esm/__fixtures__/Button/Button.component.d.ts.map +1 -1
  55. package/build/esm/__fixtures__/Button/Button.styled.d.ts +0 -1
  56. package/build/esm/__fixtures__/Button/Button.styled.d.ts.map +1 -1
  57. package/build/esm/__fixtures__/Button/index.d.ts +0 -1
  58. package/build/esm/__fixtures__/Button/index.d.ts.map +1 -1
  59. package/build/esm/__fixtures__/InlineThemedButton/InlineThemedButton.component.d.ts +0 -1
  60. package/build/esm/__fixtures__/InlineThemedButton/InlineThemedButton.component.d.ts.map +1 -1
  61. package/build/esm/__fixtures__/InlineThemedButton/index.d.ts +0 -1
  62. package/build/esm/__fixtures__/InlineThemedButton/index.d.ts.map +1 -1
  63. package/build/esm/__fixtures__/InlineVarButton/InlineVarButton.component.d.ts +0 -1
  64. package/build/esm/__fixtures__/InlineVarButton/InlineVarButton.component.d.ts.map +1 -1
  65. package/build/esm/__fixtures__/InlineVarButton/index.d.ts +0 -1
  66. package/build/esm/__fixtures__/InlineVarButton/index.d.ts.map +1 -1
  67. package/build/esm/__fixtures__/RecipeButton/RecipeButton.component.d.ts +0 -1
  68. package/build/esm/__fixtures__/RecipeButton/RecipeButton.component.d.ts.map +1 -1
  69. package/build/esm/__fixtures__/RecipeButton/index.d.ts +0 -1
  70. package/build/esm/__fixtures__/RecipeButton/index.d.ts.map +1 -1
  71. package/build/esm/__fixtures__/ReuseCSS/ReuseCSS.component.d.ts +0 -1
  72. package/build/esm/__fixtures__/ReuseCSS/ReuseCSS.component.d.ts.map +1 -1
  73. package/build/esm/__fixtures__/ReuseCSS/index.d.ts +0 -1
  74. package/build/esm/__fixtures__/ReuseCSS/index.d.ts.map +1 -1
  75. package/build/esm/__fixtures__/ReuseStyled/ReuseStyled.component.d.ts +0 -1
  76. package/build/esm/__fixtures__/ReuseStyled/ReuseStyled.component.d.ts.map +1 -1
  77. package/build/esm/__fixtures__/ReuseStyled/ReuseStyled.styled.d.ts +0 -1
  78. package/build/esm/__fixtures__/ReuseStyled/ReuseStyled.styled.d.ts.map +1 -1
  79. package/build/esm/__fixtures__/ReuseStyled/index.d.ts +0 -1
  80. package/build/esm/__fixtures__/ReuseStyled/index.d.ts.map +1 -1
  81. package/build/esm/__fixtures__/ThemedButton/ThemedButton.component.d.ts +0 -1
  82. package/build/esm/__fixtures__/ThemedButton/ThemedButton.component.d.ts.map +1 -1
  83. package/build/esm/__fixtures__/ThemedButton/ThemedButton.styled.d.ts +0 -1
  84. package/build/esm/__fixtures__/ThemedButton/ThemedButton.styled.d.ts.map +1 -1
  85. package/build/esm/__fixtures__/ThemedButton/index.d.ts +0 -1
  86. package/build/esm/__fixtures__/ThemedButton/index.d.ts.map +1 -1
  87. package/build/esm/__fixtures__/VariantButton/VariantButton.component.d.ts +0 -1
  88. package/build/esm/__fixtures__/VariantButton/VariantButton.component.d.ts.map +1 -1
  89. package/build/esm/__fixtures__/VariantButton/index.d.ts +0 -1
  90. package/build/esm/__fixtures__/VariantButton/index.d.ts.map +1 -1
  91. package/build/esm/main.d.ts +1 -0
  92. package/build/esm/main.d.ts.map +1 -1
  93. package/build/esm/main.js +1 -0
  94. package/build/esm/styled/factory.d.ts +2 -1
  95. package/build/esm/styled/factory.d.ts.map +1 -1
  96. package/build/esm/styled/types.d.ts +0 -1
  97. package/build/esm/styled/types.d.ts.map +1 -1
  98. package/build/esm/testing.d.ts +6 -0
  99. package/build/esm/testing.d.ts.map +1 -0
  100. package/build/esm/testing.js +13 -0
  101. package/package.json +24 -31
  102. package/CHANGELOG.md +0 -99
  103. package/build/cjs/styled/factory.test.d.ts +0 -2
  104. package/build/cjs/styled/factory.test.d.ts.map +0 -1
  105. package/build/cjs/styled/factory.test.js +0 -140
  106. package/build/esm/styled/factory.test.d.ts +0 -2
  107. package/build/esm/styled/factory.test.d.ts.map +0 -1
  108. package/build/esm/styled/factory.test.js +0 -138
  109. package/config/test/setup.js +0 -9
  110. package/sonar-project.properties +0 -10
  111. package/src/ThemeContext.tsx +0 -14
  112. package/src/__fixtures__/Button/Button.component.tsx +0 -7
  113. package/src/__fixtures__/Button/Button.css.ts +0 -7
  114. package/src/__fixtures__/Button/Button.styled.ts +0 -5
  115. package/src/__fixtures__/Button/index.ts +0 -7
  116. package/src/__fixtures__/InlineThemedButton/InlineThemedButton.component.tsx +0 -13
  117. package/src/__fixtures__/InlineThemedButton/InlineThemedButton.css.ts +0 -8
  118. package/src/__fixtures__/InlineThemedButton/InlineThemedButton.styled.ts +0 -7
  119. package/src/__fixtures__/InlineThemedButton/index.ts +0 -4
  120. package/src/__fixtures__/InlineVarButton/InlineVarButton.component.tsx +0 -12
  121. package/src/__fixtures__/InlineVarButton/InlineVarButton.css.ts +0 -12
  122. package/src/__fixtures__/InlineVarButton/InlineVarButton.styled.ts +0 -10
  123. package/src/__fixtures__/InlineVarButton/index.ts +0 -4
  124. package/src/__fixtures__/RecipeButton/RecipeButton.component.tsx +0 -13
  125. package/src/__fixtures__/RecipeButton/RecipeButton.css.ts +0 -22
  126. package/src/__fixtures__/RecipeButton/RecipeButton.styled.ts +0 -6
  127. package/src/__fixtures__/RecipeButton/index.ts +0 -4
  128. package/src/__fixtures__/ReuseCSS/ReuseCSS.component.tsx +0 -8
  129. package/src/__fixtures__/ReuseCSS/ReuseCSS.css.ts +0 -11
  130. package/src/__fixtures__/ReuseCSS/index.ts +0 -4
  131. package/src/__fixtures__/ReuseStyled/ReuseStyled.component.tsx +0 -6
  132. package/src/__fixtures__/ReuseStyled/ReuseStyled.css.ts +0 -6
  133. package/src/__fixtures__/ReuseStyled/ReuseStyled.styled.ts +0 -6
  134. package/src/__fixtures__/ReuseStyled/index.ts +0 -4
  135. package/src/__fixtures__/ThemedButton/ThemedButton.component.tsx +0 -6
  136. package/src/__fixtures__/ThemedButton/ThemedButton.css.ts +0 -8
  137. package/src/__fixtures__/ThemedButton/ThemedButton.styled.ts +0 -6
  138. package/src/__fixtures__/ThemedButton/index.ts +0 -4
  139. package/src/__fixtures__/VariantButton/VariantButton.component.tsx +0 -13
  140. package/src/__fixtures__/VariantButton/VariantButton.css.ts +0 -6
  141. package/src/__fixtures__/VariantButton/VariantButton.styled.ts +0 -6
  142. package/src/__fixtures__/VariantButton/index.ts +0 -4
  143. package/src/__fixtures__/index.ts +0 -9
  144. package/src/__fixtures__/theme.css.ts +0 -21
  145. package/src/main.ts +0 -8
  146. package/src/styled/constants.ts +0 -1
  147. package/src/styled/factory.test.tsx +0 -181
  148. package/src/styled/factory.tsx +0 -39
  149. package/src/styled/index.ts +0 -4
  150. package/src/styled/types.ts +0 -87
  151. package/src/styled/utils.ts +0 -56
  152. package/src/types.ts +0 -10
  153. package/tsconfig.build.cjs.json +0 -8
  154. package/tsconfig.build.esm.json +0 -11
  155. package/tsconfig.build.json +0 -5
  156. package/tsconfig.json +0 -9
  157. package/vitest.config.ts +0 -16
@@ -1,7 +0,0 @@
1
- import { Button as ButtonComponent } from './Button.component';
2
- import * as css from './Button.css';
3
- import * as styled from './Button.styled';
4
-
5
- export type { ButtonProps } from './Button.component';
6
-
7
- export const Button = Object.assign(ButtonComponent, styled, { css });
@@ -1,13 +0,0 @@
1
- import type { ButtonProps } from '../Button';
2
- import * as Theme from '../theme.css';
3
- import * as S from './InlineThemedButton.styled';
4
-
5
- export interface InlineThemedButtonProps extends ButtonProps {
6
- brandColor: string;
7
- }
8
-
9
- export const InlineThemedButton: React.FC<InlineThemedButtonProps> = ({ brandColor, onClick, children }) => (
10
- <S.Base onClick={onClick} theme={{ color: { brand: brandColor }, spacing: Theme.spacing }}>
11
- {children}
12
- </S.Base>
13
- );
@@ -1,8 +0,0 @@
1
- import { style } from '@/main';
2
-
3
- import * as Theme from '../theme.css';
4
-
5
- export const themed = style({
6
- color: Theme.vars.color.brand,
7
- borderRadius: 0,
8
- });
@@ -1,7 +0,0 @@
1
- import { styled } from '@/main';
2
-
3
- import { Button } from '../Button';
4
- import * as Theme from '../theme.css';
5
- import { themed } from './InlineThemedButton.css';
6
-
7
- export const Base = styled.button([Button.Base, themed], { theme: Theme.vars });
@@ -1,4 +0,0 @@
1
- import { InlineThemedButton as InlineThemedButtonComponent } from './InlineThemedButton.component';
2
- import * as css from './InlineThemedButton.css';
3
-
4
- export const InlineThemedButton = Object.assign(InlineThemedButtonComponent, { css });
@@ -1,12 +0,0 @@
1
- import type { ButtonProps } from '../Button';
2
- import * as S from './InlineVarButton.styled';
3
-
4
- export interface InlineVarButtonProps extends ButtonProps {
5
- brandColor: string;
6
- }
7
-
8
- export const InlineVarButton: React.FC<InlineVarButtonProps> = ({ brandColor, onClick, children }) => (
9
- <S.Base onClick={onClick} vars={{ brandColor }}>
10
- {children}
11
- </S.Base>
12
- );
@@ -1,12 +0,0 @@
1
- import { createVar, style } from '@/main';
2
-
3
- export const colorVar = createVar();
4
-
5
- export const base = style({
6
- vars: {
7
- [colorVar]: 'red',
8
- },
9
-
10
- backgroundColor: colorVar,
11
- borderRadius: 0,
12
- });
@@ -1,10 +0,0 @@
1
- import { styled } from '@/main';
2
-
3
- import { Button } from '../Button';
4
- import { base, colorVar } from './InlineVarButton.css';
5
-
6
- export const Base = styled.button([Button.Base, base], {
7
- vars: {
8
- brandColor: colorVar,
9
- },
10
- });
@@ -1,4 +0,0 @@
1
- import { InlineVarButton as InlineVarButtonComponent } from './InlineVarButton.component';
2
- import * as css from './InlineVarButton.css';
3
-
4
- export const InlineVarButton = Object.assign(InlineVarButtonComponent, { css });
@@ -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,6 +0,0 @@
1
- import { styled } from '@/main';
2
-
3
- import { Button } from '../Button';
4
- import { complex } from './RecipeButton.css';
5
-
6
- export const Base = styled.button(complex, [Button.Base]);
@@ -1,4 +0,0 @@
1
- import { RecipeButton as RecipeButtonComponent } from './RecipeButton.component';
2
- import * as css from './RecipeButton.css';
3
-
4
- export const RecipeButton = Object.assign(RecipeButtonComponent, { css });
@@ -1,8 +0,0 @@
1
- import type { ButtonProps } from '../Button';
2
- import { base } from './ReuseCSS.css';
3
-
4
- export const ReuseCSS: React.FC<ButtonProps> = ({ onClick, children }) => (
5
- <button className={base} onClick={onClick}>
6
- {children}
7
- </button>
8
- );
@@ -1,11 +0,0 @@
1
- import { style } from '@/main';
2
-
3
- import { Button } from '../Button';
4
-
5
- export const base = style([
6
- Button.css.base,
7
- {
8
- backgroundColor: 'red',
9
- borderRadius: 0,
10
- },
11
- ]);
@@ -1,4 +0,0 @@
1
- import { ReuseCSS as ReuseCSSComponent } from './ReuseCSS.component';
2
- import * as css from './ReuseCSS.css';
3
-
4
- export const ReuseCSS = Object.assign(ReuseCSSComponent, { css });
@@ -1,6 +0,0 @@
1
- import type { ButtonProps } from '../Button';
2
- import * as S from './ReuseStyled.styled';
3
-
4
- export const ReuseStyled: React.FC<ButtonProps> = ({ onClick, children }) => (
5
- <S.Base onClick={onClick}>{children}</S.Base>
6
- );
@@ -1,6 +0,0 @@
1
- import { style } from '@/main';
2
-
3
- export const override = style({
4
- border: '1px solid red',
5
- margin: 2,
6
- });
@@ -1,6 +0,0 @@
1
- import { styled } from '@/main';
2
-
3
- import { Button } from '../Button';
4
- import { override } from './ReuseStyled.css';
5
-
6
- export const Base = styled.button([Button.Base, override]);
@@ -1,4 +0,0 @@
1
- import { ReuseStyled as ReuseStyledComponent } from './ReuseStyled.component';
2
- import * as css from './ReuseStyled.css';
3
-
4
- export const ReuseStyled = Object.assign(ReuseStyledComponent, { css });
@@ -1,6 +0,0 @@
1
- import type { ButtonProps } from '../Button';
2
- import * as S from './ThemedButton.styled';
3
-
4
- export const ThemedButton: React.FC<ButtonProps> = ({ onClick, children }) => (
5
- <S.Base onClick={onClick}>{children}</S.Base>
6
- );
@@ -1,8 +0,0 @@
1
- import { style } from '@/main';
2
-
3
- import * as Theme from '../theme.css';
4
-
5
- export const themed = style({
6
- color: Theme.vars.color.brand,
7
- borderRadius: 0,
8
- });
@@ -1,6 +0,0 @@
1
- import { styled } from '@/main';
2
-
3
- import { Button } from '../Button';
4
- import { themed } from './ThemedButton.css';
5
-
6
- export const Base = styled.button([Button.Base, themed]);
@@ -1,4 +0,0 @@
1
- import { ThemedButton as ThemedButtonComponent } from './ThemedButton.component';
2
- import * as css from './ThemedButton.css';
3
-
4
- export const ThemedButton = Object.assign(ThemedButtonComponent, { css });
@@ -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,6 +0,0 @@
1
- import { styleVariants } from '@/main';
2
-
3
- export const variants = styleVariants({
4
- primary: { borderWidth: 2, borderColor: 'pink' },
5
- secondary: { borderWidth: 2, borderColor: 'blue' },
6
- });
@@ -1,6 +0,0 @@
1
- import { styled } from '@/main';
2
-
3
- import { Button } from '../Button';
4
- import { variants } from './VariantButton.css';
5
-
6
- export const Base = styled.button(variants, [Button.Base]);
@@ -1,4 +0,0 @@
1
- import { VariantButton as VariantButtonComponent } from './VariantButton.component';
2
- import * as css from './VariantButton.css';
3
-
4
- export const VariantButton = Object.assign(VariantButtonComponent, { css });
@@ -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,8 +0,0 @@
1
- export * from './styled';
2
- export * from './ThemeContext';
3
- export * from './types';
4
- export * from '@vanilla-extract/css';
5
- export * from '@vanilla-extract/dynamic';
6
- export type { RuntimeFn } from '@vanilla-extract/recipes';
7
- export { recipe } from '@vanilla-extract/recipes';
8
- export { clsx } from 'clsx';
@@ -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
- });
@@ -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
- });
@@ -1,4 +0,0 @@
1
- export * from './constants';
2
- export * from './factory';
3
- export * from './types';
4
- export * from './utils';
@@ -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;