From 67dbda5f6634a94c0fabaab90704dddf468e88fb Mon Sep 17 00:00:00 2001 From: Yuri Guller Date: Wed, 3 Feb 2021 00:01:25 +0200 Subject: [PATCH] feat(vwc-menu): issue #592 menu docs and better stories (#596) * issue #592: menu docs and better stories * issue #592: fixing some typos * adding the docs to the select * adding select documentation * adding select documentation * issue #592: docs for menu and more * issue #592: docs for menu and more * adding an initial content fo volta to vivid migration --- .../build-scripts/create-stories-from-md.mjs | 5 ++- common/context/src/partials/_layout.scss | 4 +- ...ig.mjs => context-introduction.config.mjs} | 6 +-- components/menu/readme.md | 41 ++++++++++++++--- components/menu/stories/menu-all.stories.js | 4 +- components/menu/stories/menu-basic.js | 35 +++++++++++++-- components/menu/stories/menu-cascading.js | 2 +- .../menu/stories/menu-introduction.config.mjs | 14 ++++++ components/select/readme.md | 45 ++++++++++++++++--- .../stories/select-introduction.config.mjs | 14 ++++++ .../guides/context-volta-to-vivid.config.mjs | 24 ++++++++++ docs/volta-to-vivid.md | 18 ++++++++ package.json | 1 + yarn.lock | 9 +++- 14 files changed, 195 insertions(+), 27 deletions(-) rename common/context/stories/{context-basic.config.mjs => context-introduction.config.mjs} (59%) create mode 100644 components/menu/stories/menu-introduction.config.mjs create mode 100644 components/select/stories/select-introduction.config.mjs create mode 100644 docs/stories/guides/context-volta-to-vivid.config.mjs create mode 100644 docs/volta-to-vivid.md diff --git a/.storybook/build-scripts/create-stories-from-md.mjs b/.storybook/build-scripts/create-stories-from-md.mjs index bd79c73e8d..e69f8eb73f 100644 --- a/.storybook/build-scripts/create-stories-from-md.mjs +++ b/.storybook/build-scripts/create-stories-from-md.mjs @@ -5,6 +5,7 @@ import { dirname, resolve } from 'path'; import { performance } from 'perf_hooks'; import glob from 'glob'; import showdown from 'showdown'; +import showdownHtmlEscape from 'showdown-htmlescape'; export default build; @@ -17,7 +18,7 @@ const CONFIGS_LOOKUP_PATTERN = '+(common|components|docs)/**/stories/**/*.config const DEFAULT_OUTPUT_FILE_SUFFIX = '.autogenerated.stories.js'; const FS_OPTIONS = { encoding: 'utf-8' }; -const converter = new showdown.Converter(); +const converter = new showdown.Converter({ extensions: [showdownHtmlEscape] }); converter.setFlavor('github'); async function build() { @@ -27,7 +28,7 @@ async function build() { for (const configPath of configPaths) { await processJsConfiguration(configPath); } - console.log(`... transformation of MDs to stories DONE (${Math.round(performance.now() - startTime)}ms)${os.EOL}`); + console.log(`... transformation of ${configPaths.length} MDs to stories DONE (${Math.round(performance.now() - startTime)}ms)${os.EOL}`); } function collectConfigurations() { diff --git a/common/context/src/partials/_layout.scss b/common/context/src/partials/_layout.scss index 7e162de629..aeddfb4c1b 100644 --- a/common/context/src/partials/_layout.scss +++ b/common/context/src/partials/_layout.scss @@ -33,12 +33,12 @@ padding: 20px 22px; border-radius: 6px; - :first-child { + > :first-child { margin-block-start: 0; padding-block-start: 0; } - :last-child { + > :last-child { margin-block-end: 0; padding-block-end: 0; } diff --git a/common/context/stories/context-basic.config.mjs b/common/context/stories/context-introduction.config.mjs similarity index 59% rename from common/context/stories/context-basic.config.mjs rename to common/context/stories/context-introduction.config.mjs index 65760602ba..826b7b6ede 100644 --- a/common/context/stories/context-basic.config.mjs +++ b/common/context/stories/context-introduction.config.mjs @@ -1,9 +1,9 @@ export default { sourcePath: '../readme.md', - outputName: 'context-basic', + outputName: 'context-introduction', story: { - title: 'Core/Context', - name: 'Context', + title: 'Core/Context/Introduction', + name: 'Introduction', parameters: { options: { showPanel: false, diff --git a/components/menu/readme.md b/components/menu/readme.md index e265830658..c49bf18849 100644 --- a/components/menu/readme.md +++ b/components/menu/readme.md @@ -1,6 +1,40 @@ -# vwc-menu +# `vwc-menu` -This component is an extension of [](https://github.com/material-components/material-components-web-components/tree/master/packages/menu) +`vwc-menu` is a surfacing menu component, showing up on demand, eg upon user action. +`vwc-menu` fetured with an internal list, while all LightDOM elements of it become children of that list. + +> This component is an extension of [\](https://github.com/material-components/material-components-web-components/tree/master/packages/menu). + +# Usage + +Usage example: +```html + + Item 1 + Item 2 + Item 3 + Item 4 + +``` + +`vwc-list-item` should be used for the menu items, putting any of you custom content within, including rich HTML if needed. + +> It is still consumer's responsibility to initiate `vwc-list-item`, as any other Vivid component. + +Initiate `vwc-menu` to be available in your component/application: +```javascript +import '@vonage/vwc-menu'; + +// or, to be able to use casting in TypeScript, do + +import { VWCMenu } from '@vonage/vwc-menu'; + +import '@vonage/vwc-list/vwc-list-item.js'; +``` + +# API + +`vwc-menu` exposes several APIs to provide its fuctionality, namely properties, methods and events. ## Properties @@ -12,14 +46,11 @@ This component is an extension of [](https://github.com/material-compo | `corner` | | `"TOP_LEFT" \| "TOP_RIGHT" \| "BOTTOM_LEFT" \| "BOTTOM_RIGHT" \| "TOP_START" \| "TOP_END" \| "BOTTOM_START" \| "BOTTOM_END"` | | | `defaultFocus` | | `"NONE" \| "LIST_ROOT" \| "FIRST_ITEM" \| "LAST_ITEM"` | | | `fixed` | | `boolean` | | -| `floatingLabelFoundation` | | `MDCFloatingLabelFoundation \| undefined` | | | `forceGroupSelection` | | `boolean` | | | `fullwidth` | | `boolean` | | | `index` | readonly | `MWCListIndex` | | | `innerRole` | | `"menu" \| "listbox"` | | | `items` | readonly | `ListItemBase[]` | | -| `lineRippleFoundation` | | `MDCLineRippleFoundation \| undefined` | | -| `mdcRoot` | | `MenuSurface` | Root element for MDC Foundation usage.

Define in your component with the `@query` decorator | | `menuCorner` | | `MenuCorner` | | | `multi` | | `boolean` | | | `open` | | `boolean` | | diff --git a/components/menu/stories/menu-all.stories.js b/components/menu/stories/menu-all.stories.js index 2f6075f204..1514a04754 100644 --- a/components/menu/stories/menu-all.stories.js +++ b/components/menu/stories/menu-all.stories.js @@ -11,6 +11,6 @@ export default { argTypes } -export { Basic } from './menu-basic.js'; +export { WithVWCListItem, WithVWCListItemComplex } from './menu-basic.js'; -// export { cascading } from './menu-cascading.js'; +// export { Cascading } from './menu-cascading.js'; diff --git a/components/menu/stories/menu-basic.js b/components/menu/stories/menu-basic.js index 817b134f34..496d64f2ae 100644 --- a/components/menu/stories/menu-basic.js +++ b/components/menu/stories/menu-basic.js @@ -1,18 +1,41 @@ import { html } from 'lit-element'; import { spread } from '@open-wc/lit-helpers'; -const Template = args => html` +const TemplateA = args => html`
- + Basic item 1 Basic item 2 Basic item 3 Basic item 4 -
`; + +`; -export const Basic = Template.bind({}); +export const WithVWCListItem = TemplateA.bind({}); + +const TemplateB = args => html` +
+ + + +
Basic item 1
+
+ +
Basic item 2
+
+ +
Basic item 3
+
+ +
Basic item 4
+
+
+
+`; + +export const WithVWCListItemComplex = TemplateB.bind({}); function anchorClickHandler() { const anchor = document.querySelector('#button'); @@ -20,3 +43,7 @@ function anchorClickHandler() { menu.anchor = anchor; menu.open = true; } + +function onMenuSelected(e) { + console.log(e.detail); +} diff --git a/components/menu/stories/menu-cascading.js b/components/menu/stories/menu-cascading.js index e53821a374..c7621ffc09 100644 --- a/components/menu/stories/menu-cascading.js +++ b/components/menu/stories/menu-cascading.js @@ -1,6 +1,6 @@ import { html } from 'lit-element'; -export const cascading = () => html` +export const Cascading = () => html`
diff --git a/components/menu/stories/menu-introduction.config.mjs b/components/menu/stories/menu-introduction.config.mjs new file mode 100644 index 0000000000..cef2d01854 --- /dev/null +++ b/components/menu/stories/menu-introduction.config.mjs @@ -0,0 +1,14 @@ +export default { + sourcePath: '../readme.md', + outputName: 'menu-introduction', + story: { + title: 'Components/Atoms/Menu/Introduction', + name: 'Introduction', + parameters: { + options: { + showPanel: false, + isToolshown: false + } + } + } +}; \ No newline at end of file diff --git a/components/select/readme.md b/components/select/readme.md index 7217586d9f..736c689ffa 100644 --- a/components/select/readme.md +++ b/components/select/readme.md @@ -1,28 +1,59 @@ -# vwc-select +# `vwc-select` -This component is an extension of [](https://github.com/material-components/material-components-web-components/tree/master/packages/select) +`vwc-select` is a drop-down kind of input element. + +> This component is an extension of [\](https://github.com/material-components/material-components-web-components/tree/master/packages/select). + +# Usage + +Import the component in your context, to get it initialized: +```js +import '@vonage/vwc-select/vwc-select.js'; + +// or, to be able to use casting in TypeScript, do + +import { VWCSelect } from '@vonage/vwc-select/vwc-select.js'; + +import '@vonage/vwc-list/vwc-list-item.js'; +``` + +We suggest as a rule of thumb to use `vwc-list-item` component to provide the list of options. +`vwc-list-item` is capable of holding any content, from simple text to rich HTML. + +The following should provide you with a working example: +```html + + + Item 0 + Item 1 + +``` + +Few points to pay attention to, in order to get the expected result: +* Select will preselect the first item in the list (much like the native HTML select), so if one would like to start with empty value, stare the list with an empty item +* Items MUST HAVE an attribute value with an actual values that you'd like to use in your applicative logic (except the empty choice); +the text/content within the items is for **labeling** purposes only, should be considered as not logically reliable (think of localization down the road, or some rich HTML) + +# API + +`vwc-select` exposes the following properties, methods and events: ## Properties | Property | Modifiers | Type | Description | |---------------------------|-----------|--------------------------------------------------|--------------------------------------------------| | `disabled` | | `boolean` | | -| `floatingLabelFoundation` | | `MDCFloatingLabelFoundation \| undefined` | | | `helper` | | `string` | | | `icon` | | `string` | | | `index` | readonly | `number` | | | `items` | readonly | `ListItemBase[]` | | | `label` | | `string` | | -| `lineRippleFoundation` | | `MDCLineRippleFoundation \| undefined` | | | `naturalMenuWidth` | | `boolean` | | | `outlined` | | `boolean` | | | `required` | | `boolean` | | -| `ripple` | readonly | `RippleInterface \| Promise \| undefined` | Implement ripple getter for Ripple integration with mwc-formfield | | `selected` | readonly | `ListItemBase \| null` | | | `validateOnInitialRender` | | `boolean` | | | `validationMessage` | | `string` | | -| `validity` | readonly | `ValidityState` | | -| `validityTransform` | | `((value: string, nativeValidity: ValidityState) => Partial) \| null` | | | `value` | | `string` | | ## Methods diff --git a/components/select/stories/select-introduction.config.mjs b/components/select/stories/select-introduction.config.mjs new file mode 100644 index 0000000000..786de162a3 --- /dev/null +++ b/components/select/stories/select-introduction.config.mjs @@ -0,0 +1,14 @@ +export default { + sourcePath: '../readme.md', + outputName: 'select-introduction', + story: { + title: 'Components/Atoms/Select/Introduction', + name: 'Introduction', + parameters: { + options: { + showPanel: false, + isToolshown: false + } + } + } +}; \ No newline at end of file diff --git a/docs/stories/guides/context-volta-to-vivid.config.mjs b/docs/stories/guides/context-volta-to-vivid.config.mjs new file mode 100644 index 0000000000..38ea8e611a --- /dev/null +++ b/docs/stories/guides/context-volta-to-vivid.config.mjs @@ -0,0 +1,24 @@ +import { + hrefLinkProcessing +} from '../../../.storybook/build-scripts/create-stories-from-md.mjs'; + +export default { + sourcePath: '../../volta-to-vivid.md', + outputName: 'context-volta-to-vivid', + story: { + title: 'Guides/Volta To Vivid Migration', + name: 'VoltaToVividMigration', + parameters: { + options: { + showPanel: false, + isToolshown: false + } + } + }, + htmlPostProcess: htmlText => { + return hrefLinkProcessing(htmlText, [ + ['href="../readme.md"', '?path=/story/introduction-meet-vivid--meet-vivid'], + ['href="./architecture.md"', '?path=/story/introduction-architecture--architecture'] + ]); + } +}; \ No newline at end of file diff --git a/docs/volta-to-vivid.md b/docs/volta-to-vivid.md new file mode 100644 index 0000000000..fd0652e908 --- /dev/null +++ b/docs/volta-to-vivid.md @@ -0,0 +1,18 @@ +# Summary + +[Back to main page](../readme.md) + +This page is called to concentrate few most useful and widely relevant tips and recipes for migrating the existing Vonage front end applications to Vivid. + +# Typography + +## Headers + +Headers in Vivid got size upscale to provide more flexibility and options. +Therefore, any existing header level `X` in the Volta based application should be changed to header `X+2`: +| Volta | Vivid | +|-------|-------| +| `h1` | `h3` | +| `h2` | `h4` | +| `h3` | `h5` | +| `h4` | `h6` | \ No newline at end of file diff --git a/package.json b/package.json index 5dec27002e..c61042c8ea 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,7 @@ "semver-compare": "^1.0.0", "semver-diff": "^3.1.1", "showdown": "^1.9.1", + "showdown-htmlescape": "^0.1.9", "spech": "^0.2.1", "standard-version": "^9.1.0", "tar-stream": "^2.1.4", diff --git a/yarn.lock b/yarn.lock index d83d02fa13..c6210ab5ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15142,7 +15142,14 @@ shelljs@^0.8.3, shelljs@^0.8.4: interpret "^1.0.0" rechoir "^0.6.2" -showdown@^1.9.1: +showdown-htmlescape@^0.1.9: + version "0.1.9" + resolved "https://vonagecc.jfrog.io/vonagecc/api/npm/npm/showdown-htmlescape/-/showdown-htmlescape-0.1.9.tgz#4299676a209016c9fbdabe60c38408eef3eb1800" + integrity sha1-QplnaiCQFsn72r5gw4QI7vPrGAA= + dependencies: + showdown "^1.2.3" + +showdown@^1.2.3, showdown@^1.9.1: version "1.9.1" resolved "https://vonagecc.jfrog.io/vonagecc/api/npm/npm/showdown/-/showdown-1.9.1.tgz#134e148e75cd4623e09c21b0511977d79b5ad0ef" integrity sha1-E04UjnXNRiPgnCGwURl315ta0O8=