forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: auto merge branches (ant-design#39441)
chore: merge master into feature
- Loading branch information
Showing
75 changed files
with
3,584 additions
and
2,496 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
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
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,50 @@ | ||
import * as React from 'react'; | ||
import { TinyColor, type ColorInput } from '@ctrl/tinycolor'; | ||
import { css } from '@emotion/react'; | ||
import useSiteToken from '../../../hooks/useSiteToken'; | ||
|
||
interface ColorChunkProps { | ||
children?: React.ReactNode; | ||
color?: ColorInput; | ||
} | ||
|
||
const useStyle = () => { | ||
const { token } = useSiteToken(); | ||
|
||
return { | ||
codeSpan: css` | ||
padding: 0.2em 0.4em; | ||
font-size: 0.9em; | ||
background: ${token.siteMarkdownCodeBg}; | ||
border-radius: ${token.borderRadius}px; | ||
font-family: monospace; | ||
`, | ||
dot: css` | ||
display: inline-block; | ||
width: 6px; | ||
height: 6px; | ||
border-radius: ${token.borderRadiusSM}px; | ||
margin-right: 4px; | ||
border: 1px solid ${token.colorSplit}; | ||
`, | ||
}; | ||
}; | ||
|
||
const ColorChunk: React.FC<ColorChunkProps> = (props) => { | ||
const styles = useStyle(); | ||
const { color, children } = props; | ||
|
||
const dotColor = React.useMemo(() => { | ||
const _color = new TinyColor(color).toHex8String(); | ||
return _color.endsWith('ff') ? _color.slice(0, -2) : _color; | ||
}, [color]); | ||
|
||
return ( | ||
<span css={styles.codeSpan}> | ||
<span css={styles.dot} style={{ backgroundColor: dotColor }} /> | ||
{children ?? dotColor} | ||
</span> | ||
); | ||
}; | ||
|
||
export default ColorChunk; |
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
Oops, something went wrong.