-
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.
Merge pull request #14 from computas/implement-icon
Implement icon
- Loading branch information
Showing
85 changed files
with
1,393 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { addIcons } from '../src/components/icon'; | ||
import * as cxIcons from '../src/components/icon/iconRegistry'; | ||
|
||
const iconObj = Object.entries(cxIcons) | ||
.map(([_, icon]) => icon as cxIcons.SVGIcon) | ||
.filter((icon) => !!icon.name && !!icon.data); | ||
|
||
addIcons(...iconObj); |
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,90 @@ | ||
import { | ||
Canvas, | ||
Description, | ||
IconGallery, | ||
IconItem, | ||
Meta, | ||
Source, | ||
Subtitle, | ||
Title, | ||
} from "@storybook/blocks"; | ||
|
||
import * as stories from "./icon.stories"; | ||
import * as cxIcons from "./iconRegistry"; | ||
|
||
<Meta of={stories} /> | ||
|
||
<Title /> | ||
|
||
The icon component is implemented as a web component where you manually register each icon you want to use in your application. | ||
This ensures that you only include the icons that you need in your bundle. To register an icon for use, please use the `addIcons()` | ||
function with a list of your icons, as such: | ||
|
||
<Source | ||
code={` | ||
import { addIcons } from '@computas/designsystem/icon'; | ||
import { bin, download } from '@computas/designsystem/icon/iconRegistry'; | ||
addIcons(bin, download); | ||
`} | ||
language="typescript" | ||
dark | ||
/> | ||
|
||
The registration of icons is usually done at the root level of your application, and makes the icons globally available. | ||
After registering an icon, use it through the `cx-icon` component. Start by importing the component. If you use the | ||
web component, you only need to import the component once in your app, preferably at the root level. If you use the | ||
React component, you must import the component in each place you need it. | ||
|
||
<Source | ||
code={` | ||
// Web component | ||
import '@computas/designsystem/icon'; | ||
// React | ||
import { CxIcon } from '@computas/designsystem/icon/react'; | ||
`} | ||
language="typescript" | ||
dark | ||
/> | ||
|
||
Then simply use the component and provide the name of the icon you wish to display: | ||
|
||
<Source | ||
code={` | ||
// Web component | ||
<cx-icon name="download" /> | ||
// React | ||
<CxIcon name="download" /> | ||
`} language="tsx" dark /> | ||
|
||
If you try to use an icon that is not registered, the component throws an error. | ||
|
||
<br /> | ||
## Icon overview | ||
|
||
<IconGallery> | ||
{Object.entries(cxIcons) | ||
.map(([, icon]) => icon) | ||
.filter((icon) => !!icon.data) | ||
.map((icon) => ( | ||
<IconItem name={icon.name} key={icon.name}> | ||
<cx-icon name={icon.name} /> | ||
</IconItem> | ||
))} | ||
</IconGallery> | ||
|
||
## Sizing | ||
|
||
The icon component can be sized through the `size` prop. The prop accepts the same values as our spacing tokens, in other words a number between 1 and 20. | ||
The numbers are on a relative scale, and aligns with our 4px grid. If you want your icon to be 32px, use `size="8"` (since 32 / 4 = 8). | ||
|
||
<Canvas of={stories.Sizing} /> | ||
|
||
## Color | ||
|
||
By default, the icon inherits the font color of the container it's within. | ||
If you want to use a custom color, apply a CSS class where you use the `color` property to colorize the icon. | ||
|
||
<Canvas of={stories.Color} /> |
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,59 @@ | ||
import type { Meta, StoryObj } from '@storybook/web-components'; | ||
import { html } from 'lit'; | ||
|
||
import './icon'; | ||
|
||
export default { | ||
title: 'Components/Icon', | ||
} satisfies Meta; | ||
|
||
export const Sizing: StoryObj = { | ||
render: () => html` | ||
<cx-icon name="settings" size="1" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="2" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="3" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="4" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="5" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="6" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="7" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="8" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="9" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="10" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="11" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="12" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="13" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="14" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="15" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="16" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="17" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="18" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="19" class="cx-mr-4"></cx-icon> | ||
<cx-icon name="settings" size="20"></cx-icon> | ||
`, | ||
}; | ||
|
||
export const Color: StoryObj = { | ||
render: () => html` | ||
<style> | ||
.danger-icon { | ||
color: var(--cx-color-signal-danger); | ||
} | ||
.info-icon { | ||
color: var(--cx-color-signal-info); | ||
} | ||
.success-icon { | ||
color: var(--cx-color-signal-success); | ||
} | ||
</style> | ||
<cx-icon name="star-added" size="10" class="cx-mr-4 danger-icon"></cx-icon> | ||
<cx-icon name="star-added" size="10" class="cx-mr-4 info-icon"></cx-icon> | ||
<cx-icon name="star-added" size="10" class="cx-mr-4 success-icon"></cx-icon> | ||
<button class="cx-btn__secondary"> | ||
Go forward | ||
<cx-icon name="forward" size="4"></cx-icon> | ||
</button> | ||
`, | ||
}; |
Oops, something went wrong.