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 24c8072
Show file tree
Hide file tree
Showing 27 changed files with 1,392 additions and 28 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',
],
};
45 changes: 34 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/element-vir-mono-repo",
"version": "22.1.3",
"version": "22.2.0",
"private": true,
"license": "(MIT or CC0 1.0)",
"author": {
Expand All @@ -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
2 changes: 1 addition & 1 deletion packages/element-book-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/element-book-example",
"version": "22.1.3",
"version": "22.2.0",
"private": true,
"license": "(MIT or CC0 1.0)",
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions packages/element-book/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "element-book",
"version": "22.1.3",
"version": "22.2.0",
"keywords": [
"book",
"design system",
Expand Down 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 All @@ -48,7 +47,7 @@
"lit-css-vars": "^3.0.9",
"spa-router-vir": "^4.0.3",
"typed-event-target": "^3.4.0",
"vira": "22.1.3"
"vira": "22.2.0"
},
"devDependencies": {
"@augment-vir/browser-testing": "^27.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/element-vir-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/element-vir-example",
"version": "22.1.3",
"version": "22.2.0",
"private": true,
"license": "(MIT or CC0 1.0)",
"author": {
Expand Down
3 changes: 1 addition & 2 deletions packages/element-vir/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "element-vir",
"version": "22.1.3",
"version": "22.2.0",
"keywords": [
"custom",
"web",
Expand Down 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
2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/scripts",
"version": "22.1.3",
"version": "22.2.0",
"private": true,
"license": "(MIT or CC0 1.0)",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-vir/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "theme-vir",
"version": "22.1.3",
"version": "22.2.0",
"private": true,
"description": "Create an entire web theme.",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/vira-book/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/vira-book",
"version": "22.1.3",
"version": "22.2.0",
"private": true,
"license": "(MIT or CC0 1.0)",
"author": {
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',
});
Loading

0 comments on commit 24c8072

Please sign in to comment.