Skip to content

Commit

Permalink
[minor] add vira-dropdown to vira (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
electrovir committed May 8, 2024
1 parent 6816f6c commit 27b4d54
Show file tree
Hide file tree
Showing 20 changed files with 1,348 additions and 7 deletions.
1 change: 1 addition & 0 deletions cspell.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
words: [
...baseConfig.words,
'observavir',
'listbox',
],
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"format": "virmator format",
"publish": "virmator publish \"npm run compile && npm run --workspace @electrovir/scripts update:deps && npm i && npm run test:all\"",
"test": "mono-vir for-each npm test",
"test:all": "npm run compile && concurrently -c auto -m 90% --kill-others-on-fail --colors --names tests,spelling,format,docs,build \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run build:pages\"",
"test:coverage": "npm run test coverage",
"test:all": "npm run compile && concurrently -c auto -m 90% --kill-others-on-fail --colors --names tests,spelling,format,docs,build \"npm run test\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run build:pages\"",
"test:deps": "virmator deps check",
"test:docs": "mono-vir for-each-async npm run --if-present test:docs",
"test:format": "virmator format check",
Expand Down
1 change: 0 additions & 1 deletion packages/element-book/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"docs": "virmator docs",
"start": "cd ../element-book-example && npm start",
"test": "virmator test-web",
"test:coverage": "npm run test coverage",
"test:docs": "virmator docs check",
"test:types": "npm run compile",
"test:watch": "web-test-runner --color --watch --config configs/web-test-runner.config.mjs"
Expand Down
1 change: 0 additions & 1 deletion packages/element-vir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"docs": "virmator docs",
"start": "cd ../element-vir-example && npm start",
"test": "virmator test-web",
"test:coverage": "npm run test coverage",
"test:docs": "virmator docs check",
"test:types": "tsc --pretty --noEmit"
},
Expand Down
10 changes: 8 additions & 2 deletions packages/vira-book/src/element-book/all-element-book-entries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {elementsBookPage} from './elements.book';
import {ViraDropdownItemPage} from './entries/dropdown/vira-dropdown-item.element.book';
import {dropdownPage} from './entries/dropdown/vira-dropdown.book';
import {viraDropdownPage} from './entries/dropdown/vira-dropdown.element.book';
import {iconsBookPage} from './entries/icons.book';
import {viraButtonBookPage} from './entries/vira-button.element.book';
import {viraCollapsibleBookPage} from './entries/vira-collapsible-wrapper.element.book';
Expand All @@ -9,12 +12,15 @@ import {viraLinkBookPage} from './entries/vira-link.element.book';

export const allElementBookEntries = [
elementsBookPage,

iconsBookPage,
dropdownPage,

viraButtonBookPage,
viraCollapsibleBookPage,
ViraDropdownItemPage,
viraDropdownPage,
viraIconBookPage,
viraImageBookPage,
viraInputBookPage,
viraLinkBookPage,
];
].sort((a, b) => a.title.localeCompare(b.title));
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {BookPageControlTypeEnum, defineBookPage, definePageControl} from 'element-book';
import {CSSResult, HTMLTemplateResult, css, html} from 'element-vir';
import {ViraDropdownItem} from 'vira';
import {dropdownPage} from './vira-dropdown.book';

const examples: ReadonlyArray<{
title: string;
inputs: typeof ViraDropdownItem.inputsType;
customStyle?: CSSResult;
customTemplate?: HTMLTemplateResult;
}> = [
{
title: 'unselected',
inputs: {
label: 'my label',
selected: false,
},
},
{
title: 'selected',
inputs: {
label: 'my label',
selected: true,
},
},
{
title: 'with custom child',
inputs: {
label: 'custom child',
selected: true,
},
customTemplate: html`
<b>This is custom</b>
`,
},
{
title: 'constrained width',
customStyle: css`
:host {
max-width: 100px;
}
`,
inputs: {
label: 'has more text than is possible to fit',
selected: true,
},
},
{
title: 'stretched width',
customStyle: css`
${ViraDropdownItem} {
width: 400px;
}
`,
inputs: {
label: 'wide',
selected: true,
},
},
];

export const ViraDropdownItemPage = defineBookPage({
title: ViraDropdownItem.tagName,
parent: dropdownPage,
controls: {
Selected: definePageControl({
controlType: BookPageControlTypeEnum.Dropdown,
initValue: '',
options: [
'',
'all',
'none',
],
}),
Label: definePageControl({
controlType: BookPageControlTypeEnum.Text,
initValue: '',
}),
},
elementExamplesCallback({defineExample}) {
examples.forEach((example) => {
defineExample({
title: example.title,
stateInitStatic: {
selected: example.inputs?.selected || [],
},
styles: example.customStyle,
renderCallback({controls}) {
const finalInputs: typeof ViraDropdownItem.inputsType = {
label: controls.Label || example.inputs.label,
selected: controls.Selected
? controls.Selected === 'all'
: example.inputs.selected,
};

if (example.customTemplate) {
return html`
<${ViraDropdownItem.assign(finalInputs)}>
${example.customTemplate}
</${ViraDropdownItem}>
`;
} else {
return html`
<${ViraDropdownItem.assign(finalInputs)}></${ViraDropdownItem}>
`;
}
},
});
});
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {defineBookPage} from 'element-book';
import {elementsBookPage} from '../../elements.book';

export const dropdownPage = defineBookPage({
parent: elementsBookPage,
title: 'Dropdown',
});

0 comments on commit 27b4d54

Please sign in to comment.