-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance the memoization of the setter function in `useColorMode…
…` and `useColorStyle` Hooks (#803) * feat: enhance the memoization of the setter function in `useColorMode` and `useColorStyle` Hooks * docs: update `useColorMode` and `useColorStyle` pages * docs: update color-mode and color-style pages
- Loading branch information
Showing
14 changed files
with
222 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/react-docs/pages/components/color-mode/dark-mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
Box, | ||
DarkMode, | ||
Text, | ||
useColorMode, | ||
useColorStyle, | ||
} from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const Component = () => { | ||
const [colorMode] = useColorMode(); | ||
const [colorStyle] = useColorStyle({ colorMode }); | ||
|
||
return ( | ||
<Box | ||
backgroundColor={colorStyle.background.secondary} | ||
color={colorStyle.color.primary} | ||
> | ||
<Text px="4x" py="3x"> | ||
The color mode is set to {colorMode} | ||
</Text> | ||
</Box> | ||
); | ||
}; | ||
|
||
const App = () => ( | ||
<DarkMode> | ||
<Component /> | ||
</DarkMode> | ||
); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/react-docs/pages/components/color-mode/inverted-mode-tooltip.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
Divider, | ||
InvertedMode, | ||
Text, | ||
Tooltip, | ||
} from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<Tooltip | ||
label={( | ||
<InvertedMode width={80} py="1x"> | ||
<Text>Title</Text> | ||
<Divider my="2x" /> | ||
<Text>Content</Text> | ||
</InvertedMode> | ||
)} | ||
> | ||
<Text display="inline-block">Hover Me</Text> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default App; |
32 changes: 32 additions & 0 deletions
32
packages/react-docs/pages/components/color-mode/inverted-mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
Box, | ||
InvertedMode, | ||
Text, | ||
useColorMode, | ||
useColorStyle, | ||
} from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const Component = () => { | ||
const [colorMode] = useColorMode(); | ||
const [colorStyle] = useColorStyle({ colorMode }); | ||
|
||
return ( | ||
<Box | ||
backgroundColor={colorStyle.background.secondary} | ||
color={colorStyle.color.primary} | ||
> | ||
<Text px="4x" py="3x"> | ||
The current color mode is inverted to {colorMode} mode | ||
</Text> | ||
</Box> | ||
); | ||
}; | ||
|
||
const App = () => ( | ||
<InvertedMode> | ||
<Component /> | ||
</InvertedMode> | ||
); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/react-docs/pages/components/color-mode/light-mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
Box, | ||
LightMode, | ||
Text, | ||
useColorMode, | ||
useColorStyle, | ||
} from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const Component = () => { | ||
const [colorMode] = useColorMode(); | ||
const [colorStyle] = useColorStyle({ colorMode }); | ||
|
||
return ( | ||
<Box | ||
backgroundColor={colorStyle.background.secondary} | ||
color={colorStyle.color.primary} | ||
> | ||
<Text px="4x" py="3x"> | ||
The color mode is set to {colorMode} | ||
</Text> | ||
</Box> | ||
); | ||
}; | ||
|
||
const App = () => ( | ||
<LightMode> | ||
<Component /> | ||
</LightMode> | ||
); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/react-docs/pages/components/color-style/useColorStyle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
Box, | ||
Divider, | ||
Stack, | ||
useColorMode, | ||
useColorStyle, | ||
} from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
const [colorMode] = useColorMode(); | ||
const [colorStyle] = useColorStyle({ colorMode }); | ||
const invertedPrimaryColor = { | ||
dark: 'black:primary', | ||
light: 'white:primary', | ||
}[colorMode]; | ||
|
||
return ( | ||
<Stack spacing="4x" fontFamily="mono"> | ||
Background | ||
<Box | ||
sx={{ | ||
'> *': { | ||
px: '3x', | ||
py: '2x', | ||
}, | ||
}} | ||
> | ||
<Box backgroundColor={colorStyle.background.primary}> | ||
colorStyle.background.primary | ||
</Box> | ||
<Box backgroundColor={colorStyle.background.secondary}> | ||
colorStyle.background.secondary | ||
</Box> | ||
<Box backgroundColor={colorStyle.background.tertiary}> | ||
colorStyle.background.tertiary | ||
</Box> | ||
<Box backgroundColor={colorStyle.background.inverted} color={invertedPrimaryColor}> | ||
colorStyle.background.inverted | ||
</Box> | ||
<Box backgroundColor={colorStyle.background.highlighted}> | ||
colorStyle.background.highlighted | ||
</Box> | ||
<Box backgroundColor={colorStyle.background.selected}> | ||
colorStyle.background.selected | ||
</Box> | ||
</Box> | ||
<Divider /> | ||
<Box | ||
sx={{ | ||
'> *': { | ||
px: '3x', | ||
}, | ||
'> *:not(:last-child)': { | ||
pb: '2x', | ||
}, | ||
}} | ||
> | ||
<Box color={colorStyle.color.primary}> | ||
colorStyle.color.primary | ||
</Box> | ||
<Box color={colorStyle.color.secondary}> | ||
colorStyle.color.secondary | ||
</Box> | ||
<Box color={colorStyle.color.tertiary}> | ||
colorStyle.color.tertiary | ||
</Box> | ||
<Box color={colorStyle.color.disabled}> | ||
colorStyle.color.disabled | ||
</Box> | ||
<Box color={colorStyle.color.success}> | ||
colorStyle.color.success | ||
</Box> | ||
<Box color={colorStyle.color.info}> | ||
colorStyle.color.info | ||
</Box> | ||
<Box color={colorStyle.color.warning}> | ||
colorStyle.color.warning | ||
</Box> | ||
<Box color={colorStyle.color.error}> | ||
colorStyle.color.error | ||
</Box> | ||
</Box> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default App; |
Oops, something went wrong.