Skip to content

Commit

Permalink
chore(*): update breadcrumb, modal, icon button to storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
clukhei committed Dec 20, 2024
2 parents 3c76045 + 4314a2d commit 683e55c
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ module.exports = {
"../stories/components/Accordion.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Alert.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Badge.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Breadcrumb.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Button.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Checkbox.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Divider.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Footer.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Icon.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/IconButton.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Input.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Radio.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Masthead.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Modal.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Progress.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Skeleton.@(mdx|stories.@(js|jsx|ts|tsx))",
"../stories/components/Spinner.@(mdx|stories.@(js|jsx|ts|tsx))",
Expand Down
8 changes: 4 additions & 4 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Install SGDS web components locally with the following command

```js

npm install @govtechsg/sgds-web-component@3.0.0-rc.3
npm install @govtechsg/sgds-web-component@3.0.0-rc.4

```

Expand Down Expand Up @@ -62,13 +62,13 @@ This method registers all SGDS elements up front in the Custom Elements Registry
```js
// Load global css file
<link href='https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.0.0-rc.3/themes/day.css' rel='stylesheet' type='text/css' />
<link href='https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.0.0-rc.4/themes/day.css' rel='stylesheet' type='text/css' />

// it is recommended to load a particular version when using cdn e.g. https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@1.0.2
<script src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.0.0-rc.3"></script>
<script src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.0.0-rc.4"></script>

//or load a single component e.g. Masthead
<script src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.0.0-rc.3/components/Masthead/index.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.0.0-rc.4/components/Masthead/index.umd.js"></script>

```

Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ <h2>IconList</h2>
<div class="d-flex-row">
<sgds-icon-list size="sm">
<div role="listitem">
<sgds-icon name="placeholder" size="sm"></sgds-icon>item one
<sgds-icon size="sm" name="placeholder"></sgds-icon>item one
</div>
<div role="listitem">
<sgds-icon name="placeholder" size="sm"></sgds-icon>item one
Expand Down Expand Up @@ -1159,7 +1159,7 @@ <h2>Close Button</h2>
<div class="container">
<h2>Modal</h2>
<sgds-button id="modalShowButton">Open Modal</sgds-button>
<sgds-modal size="fullscreen">
<sgds-modal>
<h2 slot="title">Modal title</h2>
<p slot="description">Modal description</p>
<p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam dictum est vitae erat molestie blandit. Pellentesque at nunc at mi auctor imperdiet eu at leo. Integer aliquam, turpis vel ultricies ornare, sem massa commodo velit, pretium dictum quam nibh et ex. Suspendisse eu dignissim libero. Donec aliquam, lacus eu pellentesque interdum, arcu nisl blandit turpis, at tincidunt purus orci ut dolor. Morbi malesuada faucibus lorem, ornare accumsan sapien lacinia vel. In enim justo, hendrerit eu mi vitae, viverra fringilla nunc. Proin semper nunc a mollis faucibus. Nam at arcu non justo congue tincidunt. Donec vehicula felis risus, et lobortis lacus fringilla eu. Proin faucibus, nisi non semper elementum, sapien nisi viverra urna, id tempus augue felis ac nibh. Nullam pulvinar magna eros. Vestibulum at orci elit. Sed convallis fermentum gravida.
Expand Down
7 changes: 4 additions & 3 deletions src/components/Breadcrumb/sgds-breadcrumb-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { html } from "lit";
import { property } from "lit/decorators.js";
import SgdsLink from "../Link/sgds-link";
import breadcrumbItemStyle from "./breadcrumb-item.css";
import SgdsElement from "../../base/sgds-element";
/**
* @summary Breadcrumb Item are navigational links used in Breadcrumb component
*
* @slot default - The title of the item
* @slot default - The link of the item. Pass in anchor tags into this slot
*/
export class SgdsBreadcrumbItem extends SgdsLink {
export class SgdsBreadcrumbItem extends SgdsElement {
static styles = [...SgdsLink.styles, breadcrumbItemStyle];
/** Specifies the url path of the breadcrumb-item. When defined, the breadcrumb-items is a anchor element. When not defined, indicates that the breadcrumb item is active. In such cases, a span element is rendered. */
/** Indicates the link matches the current location of the page. Programmatically handled by SgdsBreadcrumb to set this prop to true for the last breadcrumb item */
@property({ type: Boolean, reflect: true }) active = false;

render() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Icon/icon.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:host {
color: inherit;
display: inline-block;
display: inline-flex;
}
:host([size="sm"]) svg {
width: var(--sgds-icon-size-sm);
Expand Down
4 changes: 4 additions & 0 deletions src/components/IconButton/icon-button.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
:host {
display: inline-block;
}

.btn.btn-icon {
display: flex;
width: var(--sgds-dimension-48, 56px);
Expand Down
2 changes: 0 additions & 2 deletions src/components/IconButton/sgds-icon-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import iconButtonStyles from "./icon-button.css";
/**
* @summary An icon button is a user interface element that combines an icon and a button, serving as a clickable or tabbable component.
*
* @slot default - The slot for sgds-icon
*
* @event sgds-blur - Emitted when the button is blurred.
* @event sgds-focus - Emitted when the button is focused.
*/
Expand Down
18 changes: 3 additions & 15 deletions src/components/IconList/sgds-icon-list.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
import SgdsElement from "../../base/sgds-element";
import { html } from "lit";
import iconListStyles from "./icon-list.css";
import { property } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import SgdsIcon from "../Icon/sgds-icon";
import { ifDefined } from "lit/directives/if-defined.js";
import SgdsElement from "../../base/sgds-element";
import iconListStyles from "./icon-list.css";
/**
* @summary A IconList can be used to display content related to the same topic. Each list item begins an icon.
*
* @slot default - The list items of IconList. Each list items should have aria attribute role="list" added
* @slot default - The list items of IconList. Each list items should have aria attribute role="listitem" added
*/
export class SgdsIconList extends SgdsElement {
static styles = [...SgdsElement.styles, iconListStyles];
static dependencies = { "sgds-icon": SgdsIcon };

/** Sets the aria-role of the sgds-icon-list */
@property({ type: String, reflect: true }) role = "list";
/** The size of icon list. Changes the font-size the list items */
@property({ type: String, reflect: true }) size: "sm" | "md" | "lg" = "md";
/** The name of the icon from sgds icon library */
@property({ type: String, reflect: true }) name: string;

private _assignIconSize(buttonSize: "sm" | "md" | "lg") {
if (buttonSize === "sm") return "md";
if (buttonSize === "md") return "lg";
if (buttonSize === "lg") return "xl";
}

render() {
return html`
<div class=${classMap({ [this.size]: this.size })}>
<sgds-icon name=${ifDefined(this.name)} size=${ifDefined(this._assignIconSize(this.size))}></sgds-icon>
<slot></slot>
</div>
`;
Expand Down
13 changes: 6 additions & 7 deletions src/components/Modal/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
width: 100%;
max-width: 640px;
border-radius: var(--sgds-border-radius-md);
margin: var(--sgds-spacer-9) auto;
margin: var(--sgds-spacer-9) var(--sgds-spacer-6);
position: relative;
display:flex;
display: flex;
flex-direction: column;
max-height: calc(100% - var(--sgds-spacer-9) - var(--sgds-spacer-9))

max-height: calc(100% - var(--sgds-spacer-9) - var(--sgds-spacer-9));
}

.modal-panel:focus {
Expand All @@ -50,7 +49,7 @@
/* Ensure there's enough vertical padding for phones that don't update vh when chrome appears (e.g. iPhone) */
@media screen and (max-width: 420px) {
.modal-panel {
margin: var(--sgds-spacer-8) auto;
margin: var(--sgds-spacer-8) var(--sgds-spacer-6);
max-height: calc(100% - var(--sgds-spacer-8) - var(--sgds-spacer-8));
}
}
Expand All @@ -68,7 +67,7 @@
padding: var(--sgds-padding-xl);
}
.modal-header__title-description {
display: flex;
display: flex;
flex-direction: column;
gap: var(--sgds-gap-xs);
}
Expand Down Expand Up @@ -128,4 +127,4 @@ slot[name="description"]::slotted(*) {

[hidden] {
display: none;
}
}
13 changes: 13 additions & 0 deletions stories/templates/Breadcrumb/additional.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Pass in anchor tags in default slot of `sgds-breadcrumb-item`

For better SEO, anchor tags are to be passed by the user in the light dom or the slot of `sgds-breadcrumb-item`.
Every `sgds-breadcrumb-item` requires an anchor element.

## Overflow menu

Breadcrumb should show up to 4 breadcrumb items. Beyond that, the breadcrumb component will be re-grouped the excess items and render in a overflow dropdown menu automatically, displaying only the first , second last and last links


<Canvas of={BreadcrumbStories.Overflow}>
<Story of={BreadcrumbStories.Overflow} />
</Canvas>
29 changes: 29 additions & 0 deletions stories/templates/Breadcrumb/additional.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { html } from "lit-html";

const OverflowTemplate = args => {
return html`
<sgds-breadcrumb>
<sgds-breadcrumb-item><a href="#">Home</a></sgds-breadcrumb-item>
<sgds-breadcrumb-item><a href="#">About</a></sgds-breadcrumb-item>
<sgds-breadcrumb-item><a href="#">Contacts</a></sgds-breadcrumb-item>
<sgds-breadcrumb-item><a href="#">Link-1</a></sgds-breadcrumb-item>
<sgds-breadcrumb-item><a href="#">Link-2</a></sgds-breadcrumb-item>
<sgds-breadcrumb-item><a href="#">Link-3</a></sgds-breadcrumb-item>
<sgds-breadcrumb-item><a href="#">Link-4</a></sgds-breadcrumb-item>
</sgds-breadcrumb>
`;
};

export const Overflow = {
render: OverflowTemplate.bind({}),
name: "Overflow",
args: {},
parameters: {
docs: {
story: {
height: "500px"
}
}
},
tags: ["!dev"]
};
16 changes: 5 additions & 11 deletions stories/templates/Breadcrumb/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ import { ifDefined } from "lit/directives/if-defined.js";

export const Template = args =>
html`
<sgds-breadcrumb ariaLabel=${ifDefined(args.ariaLabel)}>
<sgds-breadcrumb-item rel=${ifDefined(args.rel)} href=${ifDefined(args.href)} target=${ifDefined(args.target)}
>Home</sgds-breadcrumb-item
>
<sgds-breadcrumb-item href="https://www.google.com">Item 1</sgds-breadcrumb-item>
<sgds-breadcrumb-item href="https://www.google.com">Item 2</sgds-breadcrumb-item>
<sgds-breadcrumb-item href="https://www.google.com">Item 3</sgds-breadcrumb-item>
<sgds-breadcrumb-item>Last Item</sgds-breadcrumb-item>
<sgds-breadcrumb>
<sgds-breadcrumb-item><a href="#">Home</a></sgds-breadcrumb-item>
<sgds-breadcrumb-item><a href="#">About</a></sgds-breadcrumb-item>
<sgds-breadcrumb-item active><a href="https://www.google.com/">Contacts</a></sgds-breadcrumb-item>
</sgds-breadcrumb>
`;
export const args = {
href: "https://www.designsystem.tech.gov.sg/"
};
export const args = {};

export const parameters = {};
41 changes: 41 additions & 0 deletions stories/templates/IconButton/additional.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Variants

The default variant is `primary`. Modify the `variant` prop to the intended value.

- Use `primary` buttons to show the key action on a page or view. Most pages should only have one primary action.
- Use `outlined` buttons next to primary buttons to indicate alternative or less pronounced actions.
- Use `ghost` button for supplementary action as they are subtle in their appearance
- Use `danger` buttons to remove things or for irreversible actions.

<Canvas of={IconButtonStories.Variants}>
<Story of={IconButtonStories.Variants} />
</Canvas>

## Sizes

The default button size is medium. Add `size="lg"`,` size="sm"` for additional sizes.

- Large buttons are used sparingly across the UI. They may be used for page components that demand attention, such as on the homepage banner.
- The medium (default) button is the standard size for buttons everywhere.
- Small button should be used sparingly and only in places where the UI is very dense.

<Canvas of={IconButtonStories.Sizes}>
<Story of={IconButtonStories.Sizes} />
</Canvas>

## Hover / Active state

To set a button's active state, set the component's `active` prop.

<Canvas of={IconButtonStories.Active}>
<Story of={IconButtonStories.Active} />
</Canvas>

## Disabled state

The disabled state indicates that an action can’t be taken until a previous action is completed.
Add `disabled` prop to the button to apply the disabled state

<Canvas of={IconButtonStories.Disabled}>
<Story of={IconButtonStories.Disabled} />
</Canvas>
62 changes: 62 additions & 0 deletions stories/templates/IconButton/additional.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { html } from "lit-html";

const VariantTemplate = args => {
return html`
<sgds-icon-button variant="primary" name="plus"></sgds-icon-button>
<sgds-icon-button variant="outline" name="dash"></sgds-icon-button>
<sgds-icon-button variant="danger" name="three-dots"></sgds-icon-button>
<sgds-icon-button variant="ghost" name="star"></sgds-icon-button>
`;
};

export const Variants = {
render: VariantTemplate.bind({}),
name: "Variants",
args: {},
parameters: {},
tags: ["!dev"]
};

const SizeTemplate = () => {
return html`<sgds-icon-button size="sm" name="plus"></sgds-icon-button>
<sgds-icon-button name="plus"></sgds-icon-button>
<sgds-icon-button size="lg" name="plus"></sgds-icon-button>`;
};

export const Sizes = {
render: SizeTemplate.bind({}),
name: "Sizes",
args: {},
parameters: {},
tags: ["!dev"]
};

const ActiveTemplate = () => {
return html`
<sgds-icon-button variant="primary" active name="plus"></sgds-icon-button>
<sgds-icon-button variant="outline" active name="dash"></sgds-icon-button>
<sgds-icon-button variant="danger" active name="three-dots"></sgds-icon-button>
<sgds-icon-button variant="ghost" active name="star"></sgds-icon-button>
`;
};

export const Active = {
render: ActiveTemplate.bind({}),
name: "Hover / Active state",
args: {},
parameters: {},
tags: ["!dev"]
};

export const Disabled = {
render: () => html`
<sgds-icon-button variant="primary" disabled name="plus"></sgds-icon-button>
<sgds-icon-button variant="outline" disabled name="dash"></sgds-icon-button>
<sgds-icon-button variant="ghost" disabled name="three-dots"></sgds-icon-button>
<sgds-icon-button variant="danger" disabled name="star"></sgds-icon-button>
`,
name: "Disabled state",
args: {},
parameters: {},
tags: ["!dev"]
};
10 changes: 8 additions & 2 deletions stories/templates/IconButton/basic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { html } from "lit-html";
import { ifDefined } from "lit/directives/if-defined.js";

export const Template = args => html`<sgds-icon-button></sgds-icon-button>`;
export const Template = args => html` <sgds-icon-button
name=${ifDefined(args.name)}
variant=${ifDefined(args.variant)}
></sgds-icon-button>`;

export const args = {};
export const args = {
name: "plus"
};

export const parameters = {};
Loading

0 comments on commit 683e55c

Please sign in to comment.