|
| 1 | +import { useToken } from '@/useToken'; |
| 2 | +import { css } from '@emotion/css'; |
| 3 | +import { transparentize } from 'polished'; |
| 4 | +import { useMemo } from 'react'; |
| 5 | + |
| 6 | +export interface AntdStylish { |
| 7 | + defaultButton: string; |
| 8 | + |
| 9 | + textInfo: string; |
| 10 | + textDefault: string; |
| 11 | + |
| 12 | + containerBgHover: string; |
| 13 | + containerBgL2: string; |
| 14 | + |
| 15 | + dataInputContainer: string; |
| 16 | + dataInputContainerFocused: string; |
| 17 | + backgroundBlur: string; |
| 18 | +} |
| 19 | + |
| 20 | +/** |
| 21 | + * 一组统一封装好的 antd 标准样式 |
| 22 | + */ |
| 23 | +export const useInternalStylish = (): AntdStylish => { |
| 24 | + const token = useToken(); |
| 25 | + |
| 26 | + return useMemo(() => { |
| 27 | + const containerBgHover = css` |
| 28 | + cursor: pointer; |
| 29 | + transition: 150ms background-color ease-in-out; |
| 30 | + &:hover { |
| 31 | + background: ${token.colorFillQuaternary}; |
| 32 | + } |
| 33 | + `; |
| 34 | + const dataInputContainerHover = css` |
| 35 | + color: ${token.colorText}; |
| 36 | + background-color: ${token.colorFillTertiary}; |
| 37 | + border-color: transparent; |
| 38 | + `; |
| 39 | + const dataInputContainerFocused = css` |
| 40 | + color: ${token.colorText} !important; |
| 41 | + background-color: ${token.colorFillQuaternary} !important; |
| 42 | + border-color: ${token.colorPrimary} !important; |
| 43 | + box-shadow: none; |
| 44 | + `; |
| 45 | + |
| 46 | + const defaultButtonBase = css` |
| 47 | + color: ${token.colorTextSecondary}; |
| 48 | + background: ${token.colorFillQuaternary}; |
| 49 | + border-color: transparent; |
| 50 | + `; |
| 51 | + |
| 52 | + return { |
| 53 | + defaultButton: css` |
| 54 | + ${defaultButtonBase}; |
| 55 | +
|
| 56 | + &:hover { |
| 57 | + color: ${token.colorText} !important; |
| 58 | + background: ${token.colorFillSecondary} !important; |
| 59 | + border-color: transparent !important; |
| 60 | + } |
| 61 | + &:focus { |
| 62 | + ${defaultButtonBase}; |
| 63 | + border-color: ${token.colorPrimary} !important; |
| 64 | + } |
| 65 | + `, |
| 66 | + |
| 67 | + textInfo: css` |
| 68 | + color: ${token.colorTextSecondary}; |
| 69 | + &:hover { |
| 70 | + color: ${token.colorText}; |
| 71 | + } |
| 72 | + `, |
| 73 | + textDefault: css` |
| 74 | + color: ${token.colorTextSecondary}; |
| 75 | + `, |
| 76 | + |
| 77 | + containerBgHover: css` |
| 78 | + cursor: pointer; |
| 79 | + transition: 150ms background-color ease-in-out; |
| 80 | +
|
| 81 | + &:hover { |
| 82 | + background: ${token.colorFillQuaternary}; |
| 83 | + } |
| 84 | + `, |
| 85 | + containerBgL2: css` |
| 86 | + ${containerBgHover}; |
| 87 | + border-radius: 4px; |
| 88 | + background: ${token.colorFillQuaternary}; |
| 89 | +
|
| 90 | + &:hover { |
| 91 | + background: ${token.colorFillTertiary}; |
| 92 | + } |
| 93 | + `, |
| 94 | + dataInputContainerFocused, |
| 95 | + dataInputContainer: css` |
| 96 | + &:hover { |
| 97 | + ${dataInputContainerHover} |
| 98 | + } |
| 99 | + &:focus { |
| 100 | + ${dataInputContainerFocused} |
| 101 | + } |
| 102 | + `, |
| 103 | + |
| 104 | + backgroundBlur: css` |
| 105 | + background: ${transparentize(0.4)(token.colorBgElevated)}; |
| 106 | + backdrop-filter: blur(10px); |
| 107 | + `, |
| 108 | + }; |
| 109 | + }, [token]); |
| 110 | +}; |
0 commit comments