Files
web/packages/design-system/.storybook/content/CornerRadius.tsx
Rasmus Langvad d0546926a9 Merged in fix/3697-prettier-configs (pull request #3396)
fix(SW-3691): Setup one prettier config for whole repo

* Setup prettierrc in root and remove other configs


Approved-by: Joakim Jäderberg
Approved-by: Linus Flood
2026-01-07 12:45:50 +00:00

100 lines
3.0 KiB
TypeScript

/* eslint-disable formatjs/no-literal-string-in-jsx */
import copy from "copy-to-clipboard"
import { kebabify } from "../../generate/utils"
import tableStyles from "./tokens.module.css"
type ThemeValue = {
resolved: string | number
alias?: string | number
}
type Theme = Record<string, ThemeValue>
type CornerRadiusProps = {
theme: Theme
}
function copyToClipboard(text: string) {
copy(text)
}
export function CornerRadius({ theme }: CornerRadiusProps) {
// Filter corner radius tokens
const cornerRadiusTokens: Theme = {}
for (const [k, v] of Object.entries(theme)) {
if (k.startsWith("Corner radius/")) {
cornerRadiusTokens[k] = v as ThemeValue
}
}
// Sort by value
const sortedTokens = Object.entries(cornerRadiusTokens).sort((a, b) => {
const aValue = typeof a[1].resolved === "number" ? a[1].resolved : 0
const bValue = typeof b[1].resolved === "number" ? b[1].resolved : 0
return aValue - bValue
})
return (
<div>
<div className={tableStyles.tableContainer}>
<table className={tableStyles.table}>
<thead className={tableStyles.tableHeader}>
<tr>
<th className={tableStyles.tableHeaderCell}>Token</th>
<th className={tableStyles.tableHeaderCell}>Pixels</th>
<th className={tableStyles.tableHeaderCell}>
Visual representation
</th>
</tr>
</thead>
<tbody>
{sortedTokens.map(([k, v]) => {
const value = typeof v.resolved === "number" ? v.resolved : 0
const valuePx = `${value}px`
return (
<tr key={k} className={tableStyles.tableRow}>
<td className={tableStyles.tableCell}>
<code
className={tableStyles.tokenName}
onClick={() => {
copyToClipboard(`var(--${kebabify(k)})`)
}}
title="Click to copy CSS variable"
>
{kebabify(k)}
</code>
</td>
<td className={tableStyles.tableCell}>
<code
className={tableStyles.value}
onClick={() => {
copyToClipboard(valuePx)
}}
title="Click to copy"
>
{valuePx}
</code>
</td>
<td className={tableStyles.tableCell}>
<div
className={tableStyles.borderRadiusPreview}
style={{
borderRadius: `${value}px`,
}}
>
{valuePx}
</div>
</td>
</tr>
)
})}
</tbody>
</table>
</div>
</div>
)
}