|
| 1 | +import { html } from 'lit'; |
| 2 | +import { ifDefined } from 'lit/directives/if-defined.js'; |
| 3 | +import { Meta, Canvas, ArgsTable, Story, Preview, Source } from '@storybook/addon-docs'; |
| 4 | + |
| 5 | +<Meta |
| 6 | + title="Components/Drawer" |
| 7 | + component="bl-drawer" |
| 8 | + parameters={{ |
| 9 | + layout: 'fullscreen', |
| 10 | + chromatic: { viewports: [1000]}, |
| 11 | + }} |
| 12 | + argTypes={{ |
| 13 | + open: { |
| 14 | + control: "boolean", |
| 15 | + default: false |
| 16 | + }, |
| 17 | + caption: { |
| 18 | + control: "text", |
| 19 | + default: "", |
| 20 | + }, |
| 21 | + externalLink: { |
| 22 | + control: "text", |
| 23 | + default: "", |
| 24 | + }, |
| 25 | + embedUrl: { |
| 26 | + control: "text", |
| 27 | + default: "", |
| 28 | + }, |
| 29 | + }} |
| 30 | +/> |
| 31 | + |
| 32 | +export const openDialog = async (event,args) => { |
| 33 | + const insideCanvas = !event.target || event.target.parentNode.parentNode.getAttribute("id") === "root"; |
| 34 | + let selector= insideCanvas ? `#root #${args.id}`: `#docs-root #${args.id}`; |
| 35 | + const drawer = document.querySelector(selector); |
| 36 | + drawer.open = true; |
| 37 | + await new Promise(resolve => setTimeout(resolve,1000)); |
| 38 | +} |
| 39 | + |
| 40 | +export const DummyContent = () => html` |
| 41 | + <div style="font: var(--bl-font-body-text-2)"> |
| 42 | + <p> |
| 43 | + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. |
| 44 | + </p> |
| 45 | + <p> |
| 46 | + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. |
| 47 | + </p> |
| 48 | + <p> |
| 49 | + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. |
| 50 | + </p> |
| 51 | + <p> |
| 52 | + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. |
| 53 | + </p> |
| 54 | + <p> |
| 55 | + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. |
| 56 | + </p> |
| 57 | + </div> |
| 58 | +` |
| 59 | + |
| 60 | +export const DrawerTemplate = (args) => html` |
| 61 | + <bl-drawer id=${ifDefined(args.id)} |
| 62 | + caption=${ifDefined(args.caption)} |
| 63 | + embed-url=${ifDefined(args.embedUrl)} |
| 64 | + external-link=${ifDefined(args.externalLink)}> |
| 65 | + ${ifDefined(args.content)} |
| 66 | + </bl-drawer> |
| 67 | +` |
| 68 | + |
| 69 | +export const StoryTemplate = (args) => html` |
| 70 | + ${DrawerTemplate(args)} |
| 71 | + <bl-button @click="${(event)=>openDialog(event,args)}">${ifDefined(args.buttonText)}</bl-button> |
| 72 | +` |
| 73 | + |
| 74 | +# Drawer |
| 75 | + |
| 76 | +A drawer presents context-specific information and/or actions without leaving the current page |
| 77 | + |
| 78 | +<bl-alert variant="warning" icon caption="Note">Inline styles in examples are only for **demo purposes**. Use regular CSS classes or tag selectors to set styles.</bl-alert> |
| 79 | + |
| 80 | +### Design Rules |
| 81 | + |
| 82 | +* Title and external link displayed on header section in drawer. Both of them are optional. |
| 83 | +* Close button always displayed on header section and drawer can be closed by clicking close button. |
| 84 | +* By default, Drawer can not close by clicking somewhere outside drawer. |
| 85 | +* Drawer appears right side on the page with full height expanded. |
| 86 | +* Title can be multiline automatically if it does not fit one line. |
| 87 | +* When drawer does not fit in its fixed size, it switches to mobile view. |
| 88 | +* There is an attribute about iframe and drawer component handle iframe rendering itself. |
| 89 | +* Only one drawer can display at the same time. When one drawer opens others will be closed. |
| 90 | + |
| 91 | +## Usage |
| 92 | + |
| 93 | +<Canvas> |
| 94 | + <Story name="Default Values" |
| 95 | + play={(event) => openDialog(event,{id:'drawer-1'})} |
| 96 | + args={{id:"drawer-1", buttonText:"default drawer", content:DummyContent()}}> |
| 97 | + {StoryTemplate.bind({})} |
| 98 | + </Story> |
| 99 | + <Story name="With caption" |
| 100 | + play={(event)=> openDialog(event,{id:'drawer-2'})} |
| 101 | + args={{id:"drawer-2", buttonText:"with caption", caption: "Caption", content:'example content'}}> |
| 102 | + {StoryTemplate.bind({})} |
| 103 | + </Story> |
| 104 | + <Story name="With long caption" |
| 105 | + play={(event) => openDialog(event,{id:'drawer-3'})} |
| 106 | + args={{id:"drawer-3", buttonText:"with long caption", caption: "This drawer has a long caption and automatically handle it", content:'example content'}}> |
| 107 | + {StoryTemplate.bind({})} |
| 108 | + </Story> |
| 109 | + <Story name="With caption and externalLink" |
| 110 | + play={(event) => openDialog(event,{id:'drawer-4'})} |
| 111 | + args={{id:"drawer-4", buttonText:"with caption and external", caption: "Caption", externalLink:"some-url", content:'example content'}}> |
| 112 | + {StoryTemplate.bind({})} |
| 113 | + </Story> |
| 114 | + <Story name="With caption and embedUrl" |
| 115 | + play={(event) => openDialog(event,{id:'drawer-5'})} |
| 116 | + args={{id:"drawer-5", buttonText:"with caption, embedUrl", caption: "Caption", embedUrl:"some-url"}}> |
| 117 | + {StoryTemplate.bind({})} |
| 118 | + </Story> |
| 119 | +</Canvas> |
| 120 | + |
| 121 | +<ArgsTable of="bl-drawer" /> |
0 commit comments