Completed MD Select
This commit is contained in:
parent
8678e1f89d
commit
6785198c62
|
@ -46,5 +46,8 @@
|
|||
],
|
||||
"version": "0.0.24",
|
||||
"license": "MIT",
|
||||
"gitHead": "115189f72a850bfb52b65ec61d932531bf327072"
|
||||
"gitHead": "115189f72a850bfb52b65ec61d932531bf327072",
|
||||
"dependencies": {
|
||||
"@material/select": "4.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,6 @@
|
|||
|
||||
const clicked = () => _bb.call(onClick)
|
||||
|
||||
$: if (icon) {
|
||||
setContext("BBMD:icon:context", "button")
|
||||
}
|
||||
|
||||
$: renderLeadingIcon = !!icon && !trailingIcon
|
||||
$: renderTrailingIcon = !!icon && trailingIcon
|
||||
</script>
|
||||
|
@ -54,11 +50,11 @@
|
|||
{disabled}
|
||||
on:click={clicked}>
|
||||
{#if renderLeadingIcon}
|
||||
<Icon {icon} />
|
||||
<Icon context="button" {icon} />
|
||||
{/if}
|
||||
<span class={labelClass}>{text}</span>
|
||||
{#if renderTrailingIcon}
|
||||
<Icon {icon} />
|
||||
<Icon context="button" {icon} />
|
||||
{/if}
|
||||
</button>
|
||||
{/if}
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
import { getContext } from "svelte"
|
||||
|
||||
export let icon = ""
|
||||
export let context = ""
|
||||
|
||||
let iconContext = getContext("BBMD:icon:context")
|
||||
let cls = iconContext
|
||||
? `material-icons mdc-${iconContext}__icon`
|
||||
: "material-icons"
|
||||
let cls = !!context ? `material-icons mdc-${context}__icon` : "material-icons"
|
||||
</script>
|
||||
|
||||
<i class={cls}>{icon}</i>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import { onMount, getContext } from "svelte"
|
||||
import { Radiobutton } from "../Radiobutton"
|
||||
import { Checkbox } from "../Checkbox"
|
||||
import Icon from "../Common/Icon.svelte"
|
||||
import ClassBuilder from "../ClassBuilder.js"
|
||||
import { generate } from "shortid"
|
||||
|
||||
|
@ -14,7 +15,7 @@
|
|||
|
||||
export let _bb
|
||||
|
||||
export let value = null
|
||||
export let value = ""
|
||||
export let text = ""
|
||||
export let secondaryText = ""
|
||||
|
||||
|
@ -83,7 +84,13 @@
|
|||
listProps && listProps.variant === "two-line" && !!secondaryText
|
||||
</script>
|
||||
|
||||
<li class={listItemClass} role="option" tabindex="0" on:click={handleClick}>
|
||||
<li
|
||||
class={listItemClass}
|
||||
role="option"
|
||||
tabindex="0"
|
||||
on:click={handleClick}
|
||||
data-value={value}
|
||||
aria-selected={isSelected}>
|
||||
{#if leadingIcon}
|
||||
<span class="mdc-list-item__graphic material-icons" aria-hidden="true">
|
||||
{leadingIcon}
|
||||
|
@ -103,10 +110,7 @@
|
|||
<Checkbox checked={isSelected} {disabled} {_bb} />
|
||||
{/if}
|
||||
{:else if trailingIcon}
|
||||
<!-- TODO: Adapt label to accept class prop to handle this. Context is insufficient -->
|
||||
<span class="mdc-list-item__meta material-icons" aria-hidden="true">
|
||||
{trailingIcon}
|
||||
</span>
|
||||
<Icon context="list-item__meta" icon={trailingIcon} />
|
||||
{/if}
|
||||
</li>
|
||||
{#if dividerAfter}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<script>
|
||||
import "@material/select/helper-text/mdc-select-helper-text"
|
||||
import { onMount } from "svelte"
|
||||
import { MDCSelectHelperText } from "@material/select/helper-text"
|
||||
import ClassBuilder from "../ClassBuilder.js"
|
||||
|
||||
const cb = new ClassBuilder("select-helper-text")
|
||||
|
||||
let helperText
|
||||
let instance
|
||||
|
||||
export let id = ""
|
||||
export let text = ""
|
||||
export let persistent = false
|
||||
|
||||
onMount(() => {
|
||||
if (!!helperText) {
|
||||
instance = new MDCSelectHelperText(helperText)
|
||||
return () => {
|
||||
instance && instance.destroy()
|
||||
instance = null
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
$: modifiers = { persistent }
|
||||
$: props = { modifiers }
|
||||
$: helperClass = cb.build({ props })
|
||||
</script>
|
||||
|
||||
<p bind:this={helperText} {id} class={helperClass}>{text}</p>
|
|
@ -0,0 +1,87 @@
|
|||
<script>
|
||||
import { onMount } from "svelte"
|
||||
import { MDCSelect } from "@material/select"
|
||||
import { generate } from "shortid"
|
||||
|
||||
import HelperText from "./HelperText.svelte"
|
||||
import NotchedOutline from "../Common/NotchedOutline.svelte"
|
||||
import FloatingLabel from "../Common/FloatingLabel.svelte"
|
||||
import createItemsStore from "../Common/ItemStore.js"
|
||||
import ClassBuilder from "../ClassBuilder.js"
|
||||
|
||||
const cb = new ClassBuilder("select", ["filled"])
|
||||
|
||||
let selectedItemsStore
|
||||
|
||||
let select
|
||||
let selectList
|
||||
let instance
|
||||
|
||||
let _helperId = ""
|
||||
|
||||
export let _bb
|
||||
export let onSelect = items => {}
|
||||
export let width = "400px"
|
||||
export let variant = "filled"
|
||||
export let disabled = false
|
||||
export let required = false
|
||||
export let label = ""
|
||||
export let helperText = ""
|
||||
|
||||
onMount(() => {
|
||||
_bb.setContext("BBMD:list:props", { singleSelection: true })
|
||||
|
||||
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
|
||||
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
|
||||
|
||||
_helperId = generate()
|
||||
|
||||
if (!!select) {
|
||||
instance = new MDCSelect(select)
|
||||
debugger
|
||||
return () => {
|
||||
instance && instance.destroy()
|
||||
instance = null
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
$: useNotchedOutline = variant === "outlined"
|
||||
$: selectList && _bb.attachChildren(selectList)
|
||||
|
||||
$: modifiers = { variant, disabled, required, noLabel: !label }
|
||||
$: props = { modifiers }
|
||||
$: selectClass = cb.build({ props })
|
||||
</script>
|
||||
|
||||
<div bind:this={select} id={_helperId} class={selectClass}>
|
||||
<div class="mdc-select__anchor" style={`width: ${width}`}>
|
||||
<i class="mdc-select__dropdown-icon" />
|
||||
<div
|
||||
id={_helperId}
|
||||
class="mdc-select__selected-text"
|
||||
aria-required={required}
|
||||
aria-controls={_helperId}
|
||||
aria-describedby={_helperId} />
|
||||
|
||||
{#if useNotchedOutline}
|
||||
<NotchedOutline>
|
||||
<FloatingLabel text={label} />
|
||||
</NotchedOutline>
|
||||
{:else}
|
||||
<FloatingLabel text={label} />
|
||||
<div class="mdc-line-ripple" />
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="mdc-select__menu mdc-menu mdc-menu-surface"
|
||||
role="listbox"
|
||||
style={`width: ${width}`}>
|
||||
|
||||
<ul bind:this={selectList} class="mdc-list" />
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<HelperText id={_helperId} text={helperText} />
|
|
@ -0,0 +1,4 @@
|
|||
@use "@material/list/mdc-list";
|
||||
@use "@material/menu-surface/mdc-menu-surface";
|
||||
@use "@material/menu/mdc-menu";
|
||||
@use "@material/select/mdc-select";
|
|
@ -0,0 +1,2 @@
|
|||
import "./_style.scss"
|
||||
export { default as Select } from "./Select.svelte";
|
|
@ -15,8 +15,8 @@
|
|||
Datatable,
|
||||
CustomersIndexTable,
|
||||
Icon,
|
||||
Menu,
|
||||
List,
|
||||
Select,
|
||||
} = props
|
||||
|
||||
let currentComponent
|
||||
|
@ -36,8 +36,8 @@
|
|||
Icon,
|
||||
Datatable,
|
||||
CustomersIndexTable,
|
||||
Menu,
|
||||
List,
|
||||
Select,
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -144,29 +144,31 @@ export const props = {
|
|||
secondaryText: "Salmon or Cod",
|
||||
value: 2,
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
Menu: {
|
||||
_component: "@budibase/materialdesign-components/Menu",
|
||||
onSelect: items => console.log("MENU SELECT", items),
|
||||
Select: {
|
||||
_component: "@budibase/materialdesign-components/Select",
|
||||
label: "Choose a Milkshake",
|
||||
helperText: "Choose a flavour",
|
||||
onSelect: selectedItem => console.log("SELECT ITEM", selectedItem),
|
||||
_children: [
|
||||
{
|
||||
_component: "@budibase/materialdesign-components/ListItem",
|
||||
_children: [],
|
||||
text: "Settings",
|
||||
text: "Orange",
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
_component: "@budibase/materialdesign-components/ListItem",
|
||||
_children: [],
|
||||
text: "Account",
|
||||
text: "Apple",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
_component: "@budibase/materialdesign-components/ListItem",
|
||||
_children: [],
|
||||
text: "Profile",
|
||||
value: 2,
|
||||
text: "Berry",
|
||||
value: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -71,7 +71,6 @@
|
|||
let useIcon = !!icon && !textarea && !fullwidth
|
||||
|
||||
if (useIcon) {
|
||||
setContext("BBMD:icon:context", "text-field")
|
||||
let iconClass = trailingIcon ? "with-trailing-icon" : "with-leading-icon"
|
||||
modifiers = { ...modifiers, iconClass }
|
||||
}
|
||||
|
@ -124,7 +123,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
|||
on:change={changed} />
|
||||
{:else}
|
||||
{#if renderLeadingIcon}
|
||||
<Icon {icon} />
|
||||
<Icon context="text-field" {icon} />
|
||||
{/if}
|
||||
<input
|
||||
{id}
|
||||
|
@ -140,7 +139,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
|||
on:focus={focus}
|
||||
on:input={changed} />
|
||||
{#if renderTrailingIcon}
|
||||
<Icon {icon} />
|
||||
<Icon context="text-field" {icon} />
|
||||
{/if}
|
||||
{#if variant !== 'outlined'}
|
||||
<div class="mdc-line-ripple" />
|
||||
|
|
|
@ -17,4 +17,5 @@ export {
|
|||
export { default as indexDatatable } from "./Templates/indexDatatable"
|
||||
export { default as recordForm } from "./Templates/recordForm"
|
||||
export { List, ListItem } from "./List"
|
||||
export {Menu} from "./Menu"
|
||||
export { Menu } from "./Menu"
|
||||
export { Select } from "./Select"
|
||||
|
|
Loading…
Reference in New Issue