-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semantic color tokens to BaseStyles (#1880)
* Add new semantic color tokens to BaseStyles * Remove unnecessary aliases * Fix border typo * Fix comments * Rename color role normal to neutral * Update special color names * Add disabled colors * Remove aliasing logic All colors are now named directly as their aliases. The 4-part token structure only serves as a mental model but is omitted in code (it will be detailed in documentation). This makes things more consistent, reduces the number of variables in global styles, and aligns closely to Figma. * Update snapshots * Document custom properties on theme page * Add changeset * Add ref to Figma in docs and fix typos
- Loading branch information
Robin Métral
authored
Jan 10, 2023
1 parent
65a7a6c
commit 38dcc5c
Showing
7 changed files
with
466 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sumup/circuit-ui': minor | ||
--- | ||
|
||
Added semantic color tokens as CSS custom properties to the `BaseStyles`. See the [documentation](https://circuit.sumup.com/?path=/docs/features-theme--page) for details. |
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,108 @@ | ||
/** | ||
* Copyright 2023, SumUp Ltd. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { css, ThemeProvider } from '@emotion/react'; | ||
import { light } from '@sumup/design-tokens'; | ||
import { | ||
Anchor, | ||
spacing, | ||
Table, | ||
ToastProvider, | ||
useNotificationToast, | ||
} from '@sumup/circuit-ui'; | ||
|
||
const getCustomProperty = (property: string) => { | ||
return getComputedStyle(document.documentElement).getPropertyValue(property); | ||
}; | ||
|
||
function Copy({ property }: { property: string }) { | ||
const { setToast } = useNotificationToast(); | ||
return ( | ||
<Anchor | ||
css={spacing({ left: 'kilo' })} | ||
size="two" | ||
/* https://caniuse.com/mdn-api_clipboard_writetext */ | ||
onClick={() => | ||
navigator.clipboard | ||
.writeText(property) | ||
.then(() => setToast({ body: 'Copied!', variant: 'confirm' })) | ||
} | ||
> | ||
Copy | ||
</Anchor> | ||
); | ||
} | ||
|
||
const getRows = (customProperties: string[][]) => { | ||
return customProperties.map(([property, value]) => [ | ||
{ | ||
children: ( | ||
<div | ||
css={css` | ||
display: flex; | ||
`} | ||
> | ||
<code>{property}</code> | ||
<Copy property={property} /> | ||
</div> | ||
), | ||
}, | ||
{ children: <code>{value}</code> }, | ||
{ | ||
align: 'right' as const, | ||
children: ( | ||
<span | ||
css={css` | ||
display: block; | ||
width: auto; | ||
height: 1em; | ||
background: var(${property}); | ||
border: 1px solid var(--cui-border-normal); | ||
`} | ||
/> | ||
), | ||
}, | ||
]); | ||
}; | ||
|
||
function ColorsTable({ customProperties }: { customProperties: string[] }) { | ||
const [colors, setColors] = useState<string[][]>(); | ||
|
||
useEffect(() => { | ||
setColors( | ||
customProperties.map((property) => [ | ||
property, | ||
getCustomProperty(property), | ||
]), | ||
); | ||
}, []); | ||
|
||
return ( | ||
<ThemeProvider theme={light}> | ||
<ToastProvider> | ||
{colors && ( | ||
<Table | ||
condensed | ||
headers={['Property name', 'Color value', 'Preview']} | ||
rows={getRows(colors)} | ||
/> | ||
)} | ||
</ToastProvider> | ||
</ThemeProvider> | ||
); | ||
} | ||
|
||
export default ColorsTable; |
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
Oops, something went wrong.
38dcc5c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
oss-circuit-ui – ./
circuit-ui.vercel.app
oss-circuit-ui.sumup-vercel.app
circuit.sumup.com
oss-circuit-ui-git-main.sumup-vercel.app