Completed MD Select
This commit is contained in:
parent
8678e1f89d
commit
6785198c62
|
@ -46,5 +46,8 @@
|
||||||
],
|
],
|
||||||
"version": "0.0.24",
|
"version": "0.0.24",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"gitHead": "115189f72a850bfb52b65ec61d932531bf327072"
|
"gitHead": "115189f72a850bfb52b65ec61d932531bf327072",
|
||||||
|
"dependencies": {
|
||||||
|
"@material/select": "4.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,6 @@
|
||||||
|
|
||||||
const clicked = () => _bb.call(onClick)
|
const clicked = () => _bb.call(onClick)
|
||||||
|
|
||||||
$: if (icon) {
|
|
||||||
setContext("BBMD:icon:context", "button")
|
|
||||||
}
|
|
||||||
|
|
||||||
$: renderLeadingIcon = !!icon && !trailingIcon
|
$: renderLeadingIcon = !!icon && !trailingIcon
|
||||||
$: renderTrailingIcon = !!icon && trailingIcon
|
$: renderTrailingIcon = !!icon && trailingIcon
|
||||||
</script>
|
</script>
|
||||||
|
@ -54,11 +50,11 @@
|
||||||
{disabled}
|
{disabled}
|
||||||
on:click={clicked}>
|
on:click={clicked}>
|
||||||
{#if renderLeadingIcon}
|
{#if renderLeadingIcon}
|
||||||
<Icon {icon} />
|
<Icon context="button" {icon} />
|
||||||
{/if}
|
{/if}
|
||||||
<span class={labelClass}>{text}</span>
|
<span class={labelClass}>{text}</span>
|
||||||
{#if renderTrailingIcon}
|
{#if renderTrailingIcon}
|
||||||
<Icon {icon} />
|
<Icon context="button" {icon} />
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
|
||||||
export let icon = ""
|
export let icon = ""
|
||||||
|
export let context = ""
|
||||||
|
|
||||||
let iconContext = getContext("BBMD:icon:context")
|
let cls = !!context ? `material-icons mdc-${context}__icon` : "material-icons"
|
||||||
let cls = iconContext
|
|
||||||
? `material-icons mdc-${iconContext}__icon`
|
|
||||||
: "material-icons"
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<i class={cls}>{icon}</i>
|
<i class={cls}>{icon}</i>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import { onMount, getContext } from "svelte"
|
import { onMount, getContext } from "svelte"
|
||||||
import { Radiobutton } from "../Radiobutton"
|
import { Radiobutton } from "../Radiobutton"
|
||||||
import { Checkbox } from "../Checkbox"
|
import { Checkbox } from "../Checkbox"
|
||||||
|
import Icon from "../Common/Icon.svelte"
|
||||||
import ClassBuilder from "../ClassBuilder.js"
|
import ClassBuilder from "../ClassBuilder.js"
|
||||||
import { generate } from "shortid"
|
import { generate } from "shortid"
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
|
|
||||||
export let _bb
|
export let _bb
|
||||||
|
|
||||||
export let value = null
|
export let value = ""
|
||||||
export let text = ""
|
export let text = ""
|
||||||
export let secondaryText = ""
|
export let secondaryText = ""
|
||||||
|
|
||||||
|
@ -83,7 +84,13 @@
|
||||||
listProps && listProps.variant === "two-line" && !!secondaryText
|
listProps && listProps.variant === "two-line" && !!secondaryText
|
||||||
</script>
|
</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}
|
{#if leadingIcon}
|
||||||
<span class="mdc-list-item__graphic material-icons" aria-hidden="true">
|
<span class="mdc-list-item__graphic material-icons" aria-hidden="true">
|
||||||
{leadingIcon}
|
{leadingIcon}
|
||||||
|
@ -103,10 +110,7 @@
|
||||||
<Checkbox checked={isSelected} {disabled} {_bb} />
|
<Checkbox checked={isSelected} {disabled} {_bb} />
|
||||||
{/if}
|
{/if}
|
||||||
{:else if trailingIcon}
|
{:else if trailingIcon}
|
||||||
<!-- TODO: Adapt label to accept class prop to handle this. Context is insufficient -->
|
<Icon context="list-item__meta" icon={trailingIcon} />
|
||||||
<span class="mdc-list-item__meta material-icons" aria-hidden="true">
|
|
||||||
{trailingIcon}
|
|
||||||
</span>
|
|
||||||
{/if}
|
{/if}
|
||||||
</li>
|
</li>
|
||||||
{#if dividerAfter}
|
{#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,
|
Datatable,
|
||||||
CustomersIndexTable,
|
CustomersIndexTable,
|
||||||
Icon,
|
Icon,
|
||||||
Menu,
|
|
||||||
List,
|
List,
|
||||||
|
Select,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
let currentComponent
|
let currentComponent
|
||||||
|
@ -36,8 +36,8 @@
|
||||||
Icon,
|
Icon,
|
||||||
Datatable,
|
Datatable,
|
||||||
CustomersIndexTable,
|
CustomersIndexTable,
|
||||||
Menu,
|
|
||||||
List,
|
List,
|
||||||
|
Select,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,29 +144,31 @@ export const props = {
|
||||||
secondaryText: "Salmon or Cod",
|
secondaryText: "Salmon or Cod",
|
||||||
value: 2,
|
value: 2,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
Menu: {
|
Select: {
|
||||||
_component: "@budibase/materialdesign-components/Menu",
|
_component: "@budibase/materialdesign-components/Select",
|
||||||
onSelect: items => console.log("MENU SELECT", items),
|
label: "Choose a Milkshake",
|
||||||
|
helperText: "Choose a flavour",
|
||||||
|
onSelect: selectedItem => console.log("SELECT ITEM", selectedItem),
|
||||||
_children: [
|
_children: [
|
||||||
{
|
{
|
||||||
_component: "@budibase/materialdesign-components/ListItem",
|
_component: "@budibase/materialdesign-components/ListItem",
|
||||||
_children: [],
|
_children: [],
|
||||||
text: "Settings",
|
text: "Orange",
|
||||||
value: 0,
|
value: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_component: "@budibase/materialdesign-components/ListItem",
|
_component: "@budibase/materialdesign-components/ListItem",
|
||||||
_children: [],
|
_children: [],
|
||||||
text: "Account",
|
text: "Apple",
|
||||||
value: 1,
|
value: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_component: "@budibase/materialdesign-components/ListItem",
|
_component: "@budibase/materialdesign-components/ListItem",
|
||||||
_children: [],
|
_children: [],
|
||||||
text: "Profile",
|
text: "Berry",
|
||||||
value: 2,
|
value: 0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -71,7 +71,6 @@
|
||||||
let useIcon = !!icon && !textarea && !fullwidth
|
let useIcon = !!icon && !textarea && !fullwidth
|
||||||
|
|
||||||
if (useIcon) {
|
if (useIcon) {
|
||||||
setContext("BBMD:icon:context", "text-field")
|
|
||||||
let iconClass = trailingIcon ? "with-trailing-icon" : "with-leading-icon"
|
let iconClass = trailingIcon ? "with-trailing-icon" : "with-leading-icon"
|
||||||
modifiers = { ...modifiers, iconClass }
|
modifiers = { ...modifiers, iconClass }
|
||||||
}
|
}
|
||||||
|
@ -124,7 +123,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
||||||
on:change={changed} />
|
on:change={changed} />
|
||||||
{:else}
|
{:else}
|
||||||
{#if renderLeadingIcon}
|
{#if renderLeadingIcon}
|
||||||
<Icon {icon} />
|
<Icon context="text-field" {icon} />
|
||||||
{/if}
|
{/if}
|
||||||
<input
|
<input
|
||||||
{id}
|
{id}
|
||||||
|
@ -140,7 +139,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
||||||
on:focus={focus}
|
on:focus={focus}
|
||||||
on:input={changed} />
|
on:input={changed} />
|
||||||
{#if renderTrailingIcon}
|
{#if renderTrailingIcon}
|
||||||
<Icon {icon} />
|
<Icon context="text-field" {icon} />
|
||||||
{/if}
|
{/if}
|
||||||
{#if variant !== 'outlined'}
|
{#if variant !== 'outlined'}
|
||||||
<div class="mdc-line-ripple" />
|
<div class="mdc-line-ripple" />
|
||||||
|
|
|
@ -17,4 +17,5 @@ export {
|
||||||
export { default as indexDatatable } from "./Templates/indexDatatable"
|
export { default as indexDatatable } from "./Templates/indexDatatable"
|
||||||
export { default as recordForm } from "./Templates/recordForm"
|
export { default as recordForm } from "./Templates/recordForm"
|
||||||
export { List, ListItem } from "./List"
|
export { List, ListItem } from "./List"
|
||||||
export {Menu} from "./Menu"
|
export { Menu } from "./Menu"
|
||||||
|
export { Select } from "./Select"
|
||||||
|
|
Loading…
Reference in New Issue