Skip to content

Commit

Permalink
chore: work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Nov 26, 2024
1 parent 166e48d commit b42b8b2
Show file tree
Hide file tree
Showing 39 changed files with 101 additions and 116 deletions.
5 changes: 1 addition & 4 deletions packages/react-docs/pages/_app.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ const EmotionCacheProvider = ({

const App = (props) => {
const customTheme = useConst(() => createTheme({
config: {
// Enable CSS variables replacement
useCSSVariables: true,
},
cssVariables: true, // Enable CSS variables replacement
components: {
// Set default props for specific components
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import React from 'react';
describe('Code', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true, // Enable CSS variables replacement
};
const { container } = render((
<Code>Hello World</Code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import {
// Use `createTheme` to provide custom configuration
<TonicProvider
theme={createTheme({
config: {
// Enable CSS variables replacement
useCSSVariables: true,
},
cssVariables: true, // Enable CSS variables replacement
})}
/>
```
Expand Down
13 changes: 3 additions & 10 deletions packages/react-docs/pages/getting-started/usage/index.page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ import {
} from '@tonic-ui/react';

const customTheme = createTheme({
config: {
// Enable CSS variables replacement
useCSSVariables: true,
},
cssVariables: true, // Enable CSS variables replacement
components: {
// Set default props for specific components
//
Expand Down Expand Up @@ -192,9 +189,7 @@ Tonic UI supports converting theme tokens defined in the theme to CSS variables.
```jsx
<TonicProvider
theme={createTheme({
config: {
useCSSVariables: true,
},
cssVariables: true, // Enable CSS variables replacement
})}
/>
```
Expand Down Expand Up @@ -303,9 +298,7 @@ import {

// Let's say you want to add more colors
const customTheme = createTheme({
config: {
useCSSVariables: true,
},
cssVariables: true, // Enable CSS variables replacement
colors: {
brand: {
90: "#1a365d",
Expand Down
5 changes: 1 addition & 4 deletions packages/react-docs/sandbox/create-react-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ const customColorStyle = merge(colorStyle, {
});
const customTheme = createTheme({
config: {
// Enable CSS variables replacement
useCSSVariables: true,
},
cssVariables: true, // Enable CSS variables replacement
components: {
// Set default props for specific components
//
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/accordion/__tests__/Accordion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import React from 'react';
describe('Accordion', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<Accordion rowGap={1}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/badge/__tests__/Badge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';
describe('Badge', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<Flex columnGap="4x">
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/button/__tests__/ButtonBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
describe('ButtonBase', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/checkbox/__tests__/Checkbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { useEffect, useRef } from 'react';
describe('Checkbox', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/code/__tests__/Code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';
describe('Code', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<Code data-testid="Code">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('DatePicker', () => {
it('should render correctly', async () => {
const user = userEvent.setup();
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const defaultValue = new Date('2024-08-01');
const inputFormat = 'yyyy-MM-dd';
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/divider/__tests__/Divider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
describe('Divider', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/drawer/__tests__/Drawer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React, { useCallback, useRef, useState } from 'react';
describe('Drawer', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { baseElement } = render((
<Drawer
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/input/__tests__/Input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Input', () => {
const sizes = ['sm', 'md', 'lg'];
const variants = ['outline', 'filled', 'flush', 'unstyled'];
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/input/__tests__/InputControl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('InputControl', () => {
const sizes = ['sm', 'md', 'lg'];
const variants = ['outline', 'filled', 'flush', 'unstyled'];
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/menu/__tests__/Menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Menu', () => {
it('should render correctly', async () => {
const user = userEvent.setup();
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<TestComponent />
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/modal/__tests__/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React, { useCallback, useRef, useState } from 'react';
describe('Modal', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { baseElement } = render((
<Modal isOpen onClose={jest.fn()}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/popover/__tests__/Popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Popover', () => {
it('should render correctly', async () => {
const user = userEvent.setup();
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<Popover>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/portal/__tests__/Portal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
describe('Portal', () => {
it('should render correctly', () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<Portal>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/progress/__tests__/Progress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
describe('LinearProgress', () => {
it('renders correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/radio/__tests__/Radio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { useEffect, useRef } from 'react';
describe('Radio', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('SearchInput', () => {
const sizes = ['sm', 'md', 'lg'];
const variants = ['outline', 'filled', 'flush', 'unstyled'];
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/stack/__tests__/Stack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';
describe('Stack', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<Stack spacing="4x">
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('Stack', () => {

it('should apply spacing between child elements', () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
render((
<Stack data-testid="stack" spacing="2x">
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/switch/__tests__/Switch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { useEffect, useRef } from 'react';
describe('Switch', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/table/__tests__/Table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Table', () => {

it('should render correctly with `flexbox` layout', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};

const { container } = render((
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Table', () => {

it('should render correctly with `table` layout', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};

const { container } = render((
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/tabs/__tests__/Tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
describe('Tabs', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<Tabs>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/text/__tests__/Text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';
describe('TextLabel', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<Text>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/text/__tests__/TextLabel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';
describe('TextLabel', () => {
it('should render correctly', async () => {
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<TextLabel data-testid="TextLabel">
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/textarea/__tests__/Textarea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Textarea', () => {
it('should render correctly', async () => {
const variants = ['outline', 'filled', 'unstyled'];
const renderOptions = {
useCSSVariables: true,
cssVariables: true,
};
const { container } = render((
<>
Expand Down
27 changes: 12 additions & 15 deletions packages/react/src/theme/__tests__/createTheme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import createTheme from '../createTheme';
describe('createTheme', () => {
it('should create a default theme', () => {
const theme = createTheme();
// Internal properties
expect(theme).toHaveProperty('config');
expect(theme).toHaveProperty('components');
// Theme properties
expect(theme).toHaveProperty('borders');
expect(theme).toHaveProperty('breakpoints');
expect(theme).toHaveProperty('colors');
Expand Down Expand Up @@ -43,21 +39,22 @@ describe('createTheme', () => {
expect(theme.components.Button.defaultProps.size).toBe('large');
});

it('should generate a CSS variable map', () => {
const theme = createTheme({ config: { useCSSVariables: true } });
expect(theme.__cssVariableMap).toBeDefined();
expect(Object.keys(theme.__cssVariableMap).length).toBeGreaterThan(0);
it('should not generate CSS variables with default configuration', () => {
const theme = createTheme();
expect(theme.vars).not.toBeDefined();
});

it('should enable CSS variables when specified', () => {
const theme = createTheme({ config: { useCSSVariables: true } });
expect(theme.config.useCSSVariables).toBe(true);
expect(theme).toHaveProperty('__cssVariableMap');
it('should generate CSS variables', () => {
const theme = createTheme({ cssVariables: true });
expect(theme.vars).toBeDefined();
expect(theme.vars.prefix).toBe('tonic');
expect(Object.keys(theme.vars).filter(x => x.startsWith('--'))[0]).toMatch(/^--tonic-/);
});

it('should apply custom prefix to CSS variables', () => {
const theme = createTheme({ config: { prefix: 'custom' } });
const cssVariableMap = theme.__cssVariableMap;
expect(Object.keys(cssVariableMap)[0]).toMatch(/^--custom-/);
const theme = createTheme({ cssVariables: { prefix: 'custom' } });
expect(theme.vars).toBeDefined();
expect(theme.vars.prefix).toBe('custom');
expect(Object.keys(theme.vars).filter(x => x.startsWith('--'))[0]).toMatch(/^--custom-/);
});
});
Loading

0 comments on commit b42b8b2

Please sign in to comment.