-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[minor] add vira-dropdown to vira (#39)
- Loading branch information
1 parent
6816f6c
commit 27b4d54
Showing
20 changed files
with
1,348 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ module.exports = { | |
words: [ | ||
...baseConfig.words, | ||
'observavir', | ||
'listbox', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/vira-book/src/element-book/entries/dropdown/vira-dropdown-item.element.book.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}> | ||
`; | ||
} | ||
}, | ||
}); | ||
}); | ||
}, | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/vira-book/src/element-book/entries/dropdown/vira-dropdown.book.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); |
Oops, something went wrong.