Commit b873c929 authored by tom's avatar tom

tags, table and toggler

parent 6a14a62c
...@@ -2,18 +2,24 @@ import type { tableAnatomy as parts } from '@chakra-ui/anatomy'; ...@@ -2,18 +2,24 @@ import type { tableAnatomy as parts } from '@chakra-ui/anatomy';
import type { ComponentMultiStyleConfig } from '@chakra-ui/theme'; import type { ComponentMultiStyleConfig } from '@chakra-ui/theme';
import { mode } from '@chakra-ui/theme-tools'; import { mode } from '@chakra-ui/theme-tools';
import type { PartsStyleFunction } from '@chakra-ui/theme-tools'; import type { PartsStyleFunction } from '@chakra-ui/theme-tools';
import getDefaultTransitionProps from '../utils/getDefaultTransitionProps';
const variantSimple: PartsStyleFunction<typeof parts> = (props) => { const variantSimple: PartsStyleFunction<typeof parts> = (props) => {
const transitionProps = getDefaultTransitionProps();
return { return {
th: { th: {
border: 0, border: 0,
color: mode('gray.500', 'gray.50')(props), color: mode('gray.500', 'gray.50')(props),
...transitionProps,
}, },
thead: { thead: {
backgroundColor: mode('gray.50', 'whiteAlpha.200')(props), backgroundColor: mode('gray.50', 'whiteAlpha.200')(props),
...transitionProps,
}, },
td: { td: {
borderColor: mode('gray.200', 'whiteAlpha.200')(props), borderColor: mode('gray.200', 'whiteAlpha.200')(props),
...transitionProps,
}, },
} }
} }
......
...@@ -2,12 +2,16 @@ import type { tagAnatomy as parts } from '@chakra-ui/anatomy'; ...@@ -2,12 +2,16 @@ import type { tagAnatomy as parts } from '@chakra-ui/anatomy';
import type { ComponentStyleConfig } from '@chakra-ui/theme'; import type { ComponentStyleConfig } from '@chakra-ui/theme';
import { mode } from '@chakra-ui/theme-tools'; import { mode } from '@chakra-ui/theme-tools';
import type { PartsStyleFunction } from '@chakra-ui/theme-tools'; import type { PartsStyleFunction } from '@chakra-ui/theme-tools';
import getDefaultTransitionProps from '../utils/getDefaultTransitionProps';
const variantGray: PartsStyleFunction<typeof parts> = (props) => { const variantGray: PartsStyleFunction<typeof parts> = (props) => {
const transitionProps = getDefaultTransitionProps();
return { return {
container: { container: {
bg: mode('gray.200', 'gray.600')(props), bg: mode('gray.200', 'gray.600')(props),
color: mode('gray.600', 'gray.50')(props), color: mode('gray.600', 'gray.50')(props),
...transitionProps,
}, },
} }
} }
......
...@@ -14,11 +14,10 @@ import { dataAttr, __DEV__ } from '@chakra-ui/utils' ...@@ -14,11 +14,10 @@ import { dataAttr, __DEV__ } from '@chakra-ui/utils'
import * as React from 'react' import * as React from 'react'
import { SunIcon, MoonIcon } from '@chakra-ui/icons' import { SunIcon, MoonIcon } from '@chakra-ui/icons'
import { useColorMode, useColorModeValue } from '@chakra-ui/react'; import { useColorMode, useColorModeValue } from '@chakra-ui/react';
import getDefaultTransitionProps from '../../theme/utils/getDefaultTransitionProps';
import styles from './ColorModeToggler.module.css'; import styles from './ColorModeToggler.module.css';
const TRANSITION_DURATION = 150;
export interface ColorModeTogglerProps export interface ColorModeTogglerProps
extends Omit<UseCheckboxProps, 'isIndeterminate'>, extends Omit<UseCheckboxProps, 'isIndeterminate'>,
Omit<HTMLChakraProps<'label'>, keyof UseCheckboxProps>, Omit<HTMLChakraProps<'label'>, keyof UseCheckboxProps>,
...@@ -38,16 +37,18 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop ...@@ -38,16 +37,18 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop
const trackBg = useColorModeValue('blackAlpha.100', 'whiteAlpha.200') const trackBg = useColorModeValue('blackAlpha.100', 'whiteAlpha.200')
const thumbBg = useColorModeValue('white', 'black') const thumbBg = useColorModeValue('white', 'black')
const transitionProps = getDefaultTransitionProps();
const trackStyles: SystemStyleObject = React.useMemo(() => ({ const trackStyles: SystemStyleObject = React.useMemo(() => ({
bg: trackBg, bg: trackBg,
}), [ trackBg ]) ...transitionProps,
}), [ trackBg, transitionProps ])
const thumbStyles: SystemStyleObject = React.useMemo(() => ({ const thumbStyles: SystemStyleObject = React.useMemo(() => ({
bg: thumbBg, bg: thumbBg,
transitionProperty: 'transform', ...transitionProps,
transitionDuration: `${ TRANSITION_DURATION }ms`, transitionProperty: 'background-color, transform',
}), [ thumbBg ]) }), [ thumbBg, transitionProps ])
return ( return (
<chakra.label <chakra.label
...@@ -60,14 +61,24 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop ...@@ -60,14 +61,24 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop
className={ styles.track } className={ styles.track }
__css={ trackStyles } __css={ trackStyles }
> >
<MoonIcon className={ styles.nightIcon } boxSize={ 4 } color={ useColorModeValue('blue.600', 'white') }/> <MoonIcon
className={ styles.nightIcon }
boxSize={ 4 }
color={ useColorModeValue('blue.600', 'white') }
{ ...transitionProps }
/>
<chakra.div <chakra.div
className={ styles.thumb } className={ styles.thumb }
data-checked={ dataAttr(state.isChecked) } data-checked={ dataAttr(state.isChecked) }
data-hover={ dataAttr(state.isHovered) } data-hover={ dataAttr(state.isHovered) }
__css={ thumbStyles } __css={ thumbStyles }
/> />
<SunIcon className={ styles.dayIcon } boxSize={ 4 } color={ useColorModeValue('gray.500', 'blue.600') }/> <SunIcon
className={ styles.dayIcon }
boxSize={ 4 }
color={ useColorModeValue('gray.500', 'blue.600') }
{ ...transitionProps }
/>
</chakra.div> </chakra.div>
</chakra.label> </chakra.label>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment