Skip to content

Commit

Permalink
feat(storybook): add icon docs file
Browse files Browse the repository at this point in the history
  • Loading branch information
bar-tay committed Jan 17, 2024
1 parent 3581239 commit dbc9d02
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import { html } from 'lit-html';
import { IconKeys } from '@boiler/icons';
import { BlrIconType } from './index';
import { BlrIconRenderFunction } from './renderFunction';
import { BlrIconType } from '../index';

import { Sizes } from '../../../globals/constants';
import { getIconName } from '../../../utils/get-icon-name';
import { calculateIconName } from '../../../utils/calculate-icon-name';
import { classMap } from 'lit/directives/class-map.js';
import { SizesType } from '../../../globals/types';
import { Themes } from '../../../foundation/_tokens-generated/index.themes';
import { Sizes } from '../../../../globals/constants';
import { Themes } from '../../../../foundation/_tokens-generated/index.themes';
import '../../../../index';
import { BlrIconRenderFunction } from '../renderFunction';
import { SizesType } from '../../../../globals/types';
import { calculateIconName } from '../../../../utils/calculate-icon-name';
import { PureIconKeys } from '@boiler/icons/icons-optimized';

const sharedStyles = html`
<style>
.wrapper {
padding: 1.25em;
display: flex;
flex-direction: column;
align-items: center;
}
.label {
font-family: Source Sans Pro, sans-serif;
font-weight: 400;
line-height: 1rem;
font-size: 2rem;
font-size: 1.5rem;
text-align: center;
}
</style>
`;

// this loads the all components instances and registers their html tags
import '../../../index';

export default {
title: 'Design System/Web Components/UI/Icon',
title: 'Design System/Web Components/UI/Icon/Icon',
argTypes: {
size: {
options: Sizes,
Expand All @@ -48,11 +47,15 @@ export default {
},
icon: {
description: 'Select the icon of the component.',
options: [undefined, ...PureIconKeys],
defaultValue: 'blr360Lg',
control: { type: 'select' },
table: {
category: 'Content / Settings',
},
},
ignoreSize: {
description: 'Choose if size of the component should be defined by the parent container.',
table: {
category: 'Content / Settings',
},
Expand All @@ -70,11 +73,11 @@ export default {
layout: 'centered',
docs: {
description: {
component: `<Markdown>
component: `<markdown>
An icon component typically displays a small, visually recognizable graphic or symbol that represents a particular function, object, or concept.
- [**Appearance**](#appearance)
- [**Size Variant**](#size-variant)
</Markdown>
</markdown>
`,
},
},
Expand All @@ -86,67 +89,67 @@ export default {
},
};

const allIcons = getIconName(IconKeys);

export const Icon = (params: BlrIconType) => {
const classes = classMap({
'icon-gallery-layout': true,
});

return html`<div class="icon-gallery row-fluid">
<ul class="icon-gallery icon-thumbnails">
${allIcons.map((icon) => {
return html`<li>
${BlrIconRenderFunction({
icon: calculateIconName(icon as string, params.size as SizesType),
size: params.size,
classMap: classes,
})}
<span class="icon-label">${icon}</span>
</li>`;
})}
</ul>
</div>`;
return html`${BlrIconRenderFunction({
icon: calculateIconName(params.icon as IconType, params.size as SizesType),
size: params.size,
})}`;
};

const defaultParams: BlrIconType = {
theme: 'Light',
size: 'lg',
icon: 'blr360Lg',
ignoreSize: false,
arialabel: 'Icon',
};

Icon.args = defaultParams;

/**
* ## Appearance
* ### Size Variant
* The Checkbox component comes in 3 sizes: SM, MD and LG.
* The Icon component comes in 6 sizes: XXS, XS, SM, MD, LG and XL.
*/
export const SizeVariant = () => {
return html`
${sharedStyles}
<div class="wrapper">
<div class="stories-checkbox">
<h3 class="label">Icon SM</h3>
${Icon({
...defaultParams,
size: 'sm',
})}
<h3 class="label">Icon MD</h3>
${Icon({
...defaultParams,
size: 'md',
})}
<h3 class="label">Icon LG</h3>
${Icon({
...defaultParams,
size: 'lg',
})}
</div>
<h3 class="label">Icon XXS</h3>
${Icon({
...defaultParams,
size: 'xxs',
})}
<h3 class="label">Icon XS</h3>
${Icon({
...defaultParams,
size: 'xs',
})}
<h3 class="label">Icon SM</h3>
${Icon({
...defaultParams,
size: 'sm',
})}
<h3 class="label">Icon MD</h3>
${Icon({
...defaultParams,
size: 'md',
})}
<h3 class="label">Icon LG</h3>
${Icon({
...defaultParams,
size: 'lg',
})}
<h3 class="label">Icon XL</h3>
${Icon({
...defaultParams,
size: 'xl',
})}
</div>
`;
};

SizeVariant.story = {
name: ' ',
};
5 changes: 3 additions & 2 deletions packages/ui-library/src/components/ui/icon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ import { ClassMapDirective } from 'lit-html/directives/class-map';
import { until } from 'lit-html/directives/until.js';
import { unsafeSVG } from 'lit-html/directives/unsafe-svg.js';
import { TAG_NAME } from './renderFunction';
import { ThemeType } from '../../../foundation/_tokens-generated/index.themes';

@customElement(TAG_NAME)
export class BlrIcon extends LitElement {
static styles = [styleCustom];

@property() icon: IconType = 'blr360Xs';
@property() size: SizesType = 'md';

@property() arialabel?: string;
@property() ignoreSize?: boolean = false;
@property() onClick?: () => void;

@property() theme: ThemeType = 'Light';
@property() classMap?: DirectiveResult<typeof ClassMapDirective>;

protected render() {
Expand Down
88 changes: 88 additions & 0 deletions packages/ui-library/src/foundation/icons/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { html } from 'lit-html';
import { IconKeys } from '@boiler/icons';
import { BlrIconType } from '../../components/ui/icon/index';
import { BlrIconRenderFunction } from '../../components/ui/icon/renderFunction';

import { Sizes } from '../../globals/constants';
import { getIconName } from '../../utils/get-icon-name';
import { calculateIconName } from '../../utils/calculate-icon-name';
import { classMap } from 'lit/directives/class-map.js';
import { SizesType } from '../../globals/types';
import { Themes } from '../_tokens-generated/index.themes';

// this loads the all components instances and registers their html tags
import '../../index';

export default {
title: 'Foundation/Icons',
argTypes: {
size: {
options: Sizes,
description: 'Select size of the component.',
control: { type: 'select' },
table: {
category: 'Appearance',
},
},
theme: {
options: Themes,
control: { type: 'select' },
table: {
category: 'Appearance',
},
},
icon: {
description: 'Select the icon of the component.',
table: {
category: 'Content / Settings',
},
},
arialabel: {
name: 'ariaLabel',
control: { type: 'text' },
description:
'Provides additional information about the elements purpose and functionality to assistive technologies, such as screen readers.',
table: {
category: 'Accessibility',
},
},
},
parameters: {
layout: 'centered',
design: {
type: 'figma',
url: 'https://www.figma.com/file/C4vgEKz8mKyulJ4gm3Qdql/%F0%9F%AB%A7-%5BBLR%5D-The-B01LER?node-id=947%3A31105&mode=dev',
},
viewMode: 'docs',
},
};

const allIcons = getIconName(IconKeys);

export const Icon = (params: BlrIconType) => {
const classes = classMap({
'icon-gallery-layout': true,
});

return html`<div class="icon-gallery row-fluid">
<ul class="icon-gallery icon-thumbnails">
${allIcons.map((icon) => {
return html`<li>
${BlrIconRenderFunction({
icon: calculateIconName(icon as string, params.size as SizesType),
size: params.size,
classMap: classes,
})}
<span class="icon-label">${icon}</span>
</li>`;
})}
</ul>
</div>`;
};

const defaultParams: BlrIconType = {
size: 'lg',
icon: 'blr360Lg',
};

Icon.args = defaultParams;

0 comments on commit dbc9d02

Please sign in to comment.