@splendidlabz/svelte 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +3 -0
- package/CHANGELOG.md +91 -0
- package/actions/breakpoint-observer.js +71 -0
- package/actions/index.js +6 -0
- package/actions/portal.js +20 -0
- package/actions/resize-observer.js +43 -0
- package/actions/scroll-observer.js +47 -0
- package/common.js +21 -0
- package/components/Accordion/Accordion.svelte +108 -0
- package/components/Accordion/index.js +3 -0
- package/components/Breadcrumbs/Breadcrumbs.svelte +69 -0
- package/components/Breadcrumbs/Crumb.svelte +37 -0
- package/components/Breadcrumbs/CrumbCustom.svelte +14 -0
- package/components/Breadcrumbs/index.js +5 -0
- package/components/BrowserFrame.svelte +37 -0
- package/components/BrowserWithTabs.svelte +28 -0
- package/components/CQChecker/CQChecker.astro +20 -0
- package/components/CQChecker/CQChecker.svelte +89 -0
- package/components/Callout/Callout.svelte +17 -0
- package/components/Callout/index.js +3 -0
- package/components/Codepen/Codepen.astro +29 -0
- package/components/Codepen/Codepen.svelte +24 -0
- package/components/Codepen/index.js +3 -0
- package/components/ContentList/ContentList-old.svelte +117 -0
- package/components/ContentList/ContentList.svelte +68 -0
- package/components/ContentList/index.js +3 -0
- package/components/Disclosure/Drawer/Drawer.svelte +35 -0
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +31 -0
- package/components/Disclosure/Drawer/DrawerContent-wrecked.svelte +198 -0
- package/components/Disclosure/Drawer/DrawerContent.svelte +164 -0
- package/components/Disclosure/Drawer/DrawerTrigger.svelte +32 -0
- package/components/Disclosure/Drawer/drawer.js +112 -0
- package/components/Disclosure/Drawer/index.js +6 -0
- package/components/Disclosure/Dropdown/DropdownContent.svelte +15 -0
- package/components/Disclosure/Dropdown/DropdownTrigger.svelte +14 -0
- package/components/Disclosure/Dropdown/dropdown.js +4 -0
- package/components/Disclosure/Dropdown/index.js +4 -0
- package/components/Disclosure/Modal/ModalContent.svelte +3 -0
- package/components/Disclosure/Modal/ModalTrigger.svelte +33 -0
- package/components/Disclosure/Modal/exit-intent.js +17 -0
- package/components/Disclosure/Modal/modal.js +13 -0
- package/components/Disclosure/Popover/PopoverCloseButton.svelte +29 -0
- package/components/Disclosure/Popover/PopoverContent.svelte +107 -0
- package/components/Disclosure/Popover/PopoverTrigger.svelte +33 -0
- package/components/Disclosure/Popover/floating.js +171 -0
- package/components/Disclosure/Popover/index.js +5 -0
- package/components/Disclosure/Popover/popover.js +18 -0
- package/components/Disclosure/Popover/references/FollowTheMouse.svelte +45 -0
- package/components/Disclosure/Tooltip/Tooltip.svelte +14 -0
- package/components/Disclosure/Tooltip/TooltipContent.svelte +7 -0
- package/components/Disclosure/Tooltip/TooltipTrigger.svelte +33 -0
- package/components/Disclosure/Tooltip/index.js +5 -0
- package/components/Disclosure/Tooltip/tooltip.js +22 -0
- package/components/Disclosure/disclosure-store.js +48 -0
- package/components/Disclosure/disclosure.js +439 -0
- package/components/Disclosure/index.js +3 -0
- package/components/Disclosure/state.svelte.js +138 -0
- package/components/FancyList/FancyList.svelte +49 -0
- package/components/FancyList/index.js +3 -0
- package/components/Form/Button.svelte +24 -0
- package/components/Form/Checkbox.svelte +80 -0
- package/components/Form/Checkboxes.svelte +48 -0
- package/components/Form/Combobox/AutocompleteInput.svelte +63 -0
- package/components/Form/Combobox/AutocompleteOptions.svelte +74 -0
- package/components/Form/Combobox/TimepickerInput.svelte +81 -0
- package/components/Form/Combobox/TimepickerOptions.svelte +100 -0
- package/components/Form/Combobox/autocomplete-matching.js +114 -0
- package/components/Form/Combobox/autocomplete.js +393 -0
- package/components/Form/Combobox/combobox-store.js +65 -0
- package/components/Form/Combobox/combobox.js +359 -0
- package/components/Form/Combobox/index.js +14 -0
- package/components/Form/Combobox/timepicker.js +119 -0
- package/components/Form/Form.svelte +62 -0
- package/components/Form/Hidden.svelte +16 -0
- package/components/Form/Radio.svelte +69 -0
- package/components/Form/Radios.svelte +50 -0
- package/components/Form/Select.svelte +127 -0
- package/components/Form/Switch.svelte +50 -0
- package/components/Form/TextInput.svelte +87 -0
- package/components/Form/Textarea.svelte +103 -0
- package/components/Form/check.svg +3 -0
- package/components/Form/index.js +12 -0
- package/components/Highlight/Highlight.svelte +27 -0
- package/components/Highlight/_Highlight.scss +19 -0
- package/components/Highlight/index.js +2 -0
- package/components/Image.svelte +24 -0
- package/components/InteractiveRegion/InteractiveRegion.svelte +47 -0
- package/components/InteractiveRegion/index.js +3 -0
- package/components/List/Lia.svelte +12 -0
- package/components/List/NestedListItem.svelte +50 -0
- package/components/List/index.js +3 -0
- package/components/Markdown/Markdown.svelte +35 -0
- package/components/Masonry/Masonry.svelte +79 -0
- package/components/Masonry/index.js +3 -0
- package/components/PerspectiveHover/PerspectiveHover.svelte +10 -0
- package/components/PerspectiveHover/perspective-hover.js +46 -0
- package/components/Populate/ConditionalPopulate.svelte +33 -0
- package/components/Populate/Populate.svelte +45 -0
- package/components/Populate/actions.js +29 -0
- package/components/Populate/get-value.js +17 -0
- package/components/Populate/index.js +4 -0
- package/components/Portal.svelte +27 -0
- package/components/PushToLocalStorage.svelte +30 -0
- package/components/Resizer/Resizer.svelte +32 -0
- package/components/Resizer/draggable.js +23 -0
- package/components/Resizer/index.js +3 -0
- package/components/Resizer/resizer.js +133 -0
- package/components/SVG/SVG.svelte +120 -0
- package/components/Scrambler/Scrambler.svelte +27 -0
- package/components/Scrambler/index.js +3 -0
- package/components/Spotlight/PointerPosition.js +32 -0
- package/components/Spotlight/Spotlight.svelte +9 -0
- package/components/Status.svelte +27 -0
- package/components/Switcheroo/Switcheroo.svelte +71 -0
- package/components/Switcheroo/index.js +3 -0
- package/components/Table/RowGroup.svelte +8 -0
- package/components/Table/Table.svelte +23 -0
- package/components/Table/Td.svelte +20 -0
- package/components/Table/Th.svelte +27 -0
- package/components/Table/Thead.svelte +8 -0
- package/components/Table/Tr.svelte +8 -0
- package/components/Table/index.js +17 -0
- package/components/Table/table.js +35 -0
- package/components/Tabs/Tab.svelte +12 -0
- package/components/Tabs/Tablist.svelte +62 -0
- package/components/Tabs/Tabpanel.svelte +10 -0
- package/components/Tabs/Tabpanels.svelte +12 -0
- package/components/Tabs/index.js +6 -0
- package/components/Tabs/tab-store.js +60 -0
- package/components/Tabs/tabs.js +364 -0
- package/components/Tabs-Old/Tab.svelte +9 -0
- package/components/Tabs-Old/Tablist.svelte +13 -0
- package/components/Tabs-Old/Tabpanel.svelte +10 -0
- package/components/Tabs-Old/Tabpanels.svelte +14 -0
- package/components/Tabs-Old/Tabs.svelte +83 -0
- package/components/Tabs-Old/index.js +7 -0
- package/components/Tabs-Old/tabs.js +306 -0
- package/components/Textwall/Repeat.svelte +10 -0
- package/components/Textwall/Textwall.svelte +30 -0
- package/components/Textwall/index.js +4 -0
- package/components/Typewriter/Typewriter.svelte +70 -0
- package/components/Typewriter/index.js +3 -0
- package/components/Video.svelte +46 -0
- package/components/Vimeo.svelte +18 -0
- package/components/Wrapper.svelte +22 -0
- package/components/Youtube.svelte +15 -0
- package/components/_shared/accessibility.js +9 -0
- package/components/_shared/key.js +1 -0
- package/components/_shared/transitions.js +48 -0
- package/components/_shared/use-actions.js +31 -0
- package/index.js +35 -0
- package/jsconfig.json +5 -0
- package/package.json +39 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { toTitle } from '@splendidlabz/utils'
|
|
3
|
+
import { randomString } from '@splendidlabz/utils/dom'
|
|
4
|
+
import SVG from '../SVG/SVG.svelte'
|
|
5
|
+
import TextInput from './TextInput.svelte'
|
|
6
|
+
let klass = ''
|
|
7
|
+
export { klass as class }
|
|
8
|
+
|
|
9
|
+
export let icon = null
|
|
10
|
+
export let iconClass = null
|
|
11
|
+
export let fieldClass = ''
|
|
12
|
+
export let labelClass = ''
|
|
13
|
+
|
|
14
|
+
export let id = null
|
|
15
|
+
export let name
|
|
16
|
+
export let label = null
|
|
17
|
+
export let value = 'on'
|
|
18
|
+
export let checked = false
|
|
19
|
+
export let disabled = null
|
|
20
|
+
export let readonly = null
|
|
21
|
+
export let ref = null
|
|
22
|
+
export let alwaysSend = false
|
|
23
|
+
export let hasInput = false
|
|
24
|
+
|
|
25
|
+
const origValue = value
|
|
26
|
+
id = id || randomString(8)
|
|
27
|
+
|
|
28
|
+
if (!name) throw new Error('Checkbox requires a name')
|
|
29
|
+
|
|
30
|
+
// Create label if not provided
|
|
31
|
+
if (name && !label && label !== '') label = toTitle(name)
|
|
32
|
+
|
|
33
|
+
$: {
|
|
34
|
+
if (checked) value = origValue
|
|
35
|
+
if (!checked) value = 'off'
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<div class="Checkbox {klass}" class:checked class:disabled class:readonly>
|
|
40
|
+
<div class="Checkmark">
|
|
41
|
+
<input
|
|
42
|
+
class="Field {fieldClass}"
|
|
43
|
+
type="checkbox"
|
|
44
|
+
{id}
|
|
45
|
+
{name}
|
|
46
|
+
{value}
|
|
47
|
+
bind:checked
|
|
48
|
+
bind:this={ref}
|
|
49
|
+
on:change
|
|
50
|
+
disabled={disabled || readonly}
|
|
51
|
+
{...$$restProps}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
{#if readonly || alwaysSend}
|
|
55
|
+
<input type="hidden" {name} {checked} {value} />
|
|
56
|
+
{/if}
|
|
57
|
+
|
|
58
|
+
{#if icon}
|
|
59
|
+
<SVG class={iconClass} {icon} />
|
|
60
|
+
{:else}
|
|
61
|
+
<svg viewBox="0 0 24 24" fill="none">
|
|
62
|
+
<path
|
|
63
|
+
d="M5 12L10 17L20 7"
|
|
64
|
+
stroke="black"
|
|
65
|
+
stroke-width="2"
|
|
66
|
+
stroke-linecap="round"
|
|
67
|
+
stroke-linejoin="round"
|
|
68
|
+
/>
|
|
69
|
+
</svg>
|
|
70
|
+
{/if}
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
{#if label}
|
|
74
|
+
<label class="Label {labelClass}" for={id}>{label}</label>
|
|
75
|
+
{/if}
|
|
76
|
+
|
|
77
|
+
{#if hasInput}
|
|
78
|
+
<TextInput {name} />
|
|
79
|
+
{/if}
|
|
80
|
+
</div>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Checkbox from './Checkbox.svelte'
|
|
3
|
+
let klass = ''
|
|
4
|
+
export { klass as class }
|
|
5
|
+
export let legendClass = ''
|
|
6
|
+
export let checkboxesClass = ''
|
|
7
|
+
|
|
8
|
+
export let legend = '' // Optional legend for the fieldset
|
|
9
|
+
export let checkboxes = [] // Array of objects that contain name and label
|
|
10
|
+
export let checked = false
|
|
11
|
+
export let disabled = null
|
|
12
|
+
export let readonly = null
|
|
13
|
+
export let alwaysSend = null
|
|
14
|
+
export let ref = null
|
|
15
|
+
|
|
16
|
+
const props = {
|
|
17
|
+
checked,
|
|
18
|
+
disabled,
|
|
19
|
+
readonly,
|
|
20
|
+
alwaysSend,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
checkboxes = checkboxes.map(checkbox => {
|
|
24
|
+
if (typeof checkbox === 'string') checkbox = { name: checkbox }
|
|
25
|
+
return { checked, ...checkbox }
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// Todo: Indeterminate checkboxes
|
|
29
|
+
// Useful for groups of checkboxes. Add later.
|
|
30
|
+
// inputInstance.indeterminate = true
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<fieldset class="Fieldset {klass}" on:change bind:this={ref} {...$$restProps}>
|
|
34
|
+
{#if legend}
|
|
35
|
+
<legend class="Legend {legendClass}">{legend}</legend>
|
|
36
|
+
{/if}
|
|
37
|
+
|
|
38
|
+
<div class="Checkboxes {checkboxesClass}">
|
|
39
|
+
{#each checkboxes as checkbox}
|
|
40
|
+
<Checkbox
|
|
41
|
+
{...props}
|
|
42
|
+
{...checkbox}
|
|
43
|
+
bind:ref={checkbox.ref}
|
|
44
|
+
bind:checked={checkbox.checked}
|
|
45
|
+
/>
|
|
46
|
+
{/each}
|
|
47
|
+
</div>
|
|
48
|
+
</fieldset>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import { disclosureTrigger } from '../../Disclosure/disclosure.js'
|
|
4
|
+
import TextInput from '../TextInput.svelte'
|
|
5
|
+
import {
|
|
6
|
+
AUTOCOMPLETE_INPUT_OPT_KEYS,
|
|
7
|
+
autocompleteInput,
|
|
8
|
+
DEFAULT_AUTOCOMPLETE_INPUT_OPTS,
|
|
9
|
+
} from './autocomplete.js'
|
|
10
|
+
import { comboboxes, updateCombobox } from './combobox-store.js'
|
|
11
|
+
|
|
12
|
+
let klass = ''
|
|
13
|
+
export { klass as class }
|
|
14
|
+
export let target
|
|
15
|
+
export let haystack = []
|
|
16
|
+
export let options = {}
|
|
17
|
+
|
|
18
|
+
if (!target) throw new Error('AutocompleteInput requires a target prop')
|
|
19
|
+
|
|
20
|
+
const opts = {
|
|
21
|
+
...DEFAULT_AUTOCOMPLETE_INPUT_OPTS.disclosure,
|
|
22
|
+
...DEFAULT_AUTOCOMPLETE_INPUT_OPTS.input,
|
|
23
|
+
...options,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { picked: autocompleteInputOpts, omitted: disclosureOpts } =
|
|
27
|
+
splitObject(opts, AUTOCOMPLETE_INPUT_OPT_KEYS)
|
|
28
|
+
|
|
29
|
+
const listboxId = target + '-autocomplete'
|
|
30
|
+
let inputRef
|
|
31
|
+
let Box
|
|
32
|
+
|
|
33
|
+
$: {
|
|
34
|
+
Box = $comboboxes.find(c => c.id === listboxId)
|
|
35
|
+
if (!Box) break $
|
|
36
|
+
|
|
37
|
+
// Updates haystack if user fetches it later
|
|
38
|
+
Box.state.haystack = haystack
|
|
39
|
+
updateCombobox(Box)
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<TextInput
|
|
44
|
+
class="AutocompleteInput {klass}"
|
|
45
|
+
{target}
|
|
46
|
+
bind:ref={inputRef}
|
|
47
|
+
role="combobox"
|
|
48
|
+
aria-autocomplete="list"
|
|
49
|
+
aria-controls={listboxId}
|
|
50
|
+
aria-owns={listboxId}
|
|
51
|
+
aria-activedescendant={Box?.state.activeDescendantId || null}
|
|
52
|
+
actions={[
|
|
53
|
+
[disclosureTrigger, { options: disclosureOpts }],
|
|
54
|
+
[
|
|
55
|
+
autocompleteInput,
|
|
56
|
+
{
|
|
57
|
+
state: { haystack },
|
|
58
|
+
options: autocompleteInputOpts,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
]}
|
|
62
|
+
{...$$restProps}
|
|
63
|
+
/>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import PopoverContent from '../../Disclosure/Popover/PopoverContent.svelte'
|
|
4
|
+
import {
|
|
5
|
+
AUTOCOMPLETE_CONTENT_KEYS,
|
|
6
|
+
autocompleteOptions,
|
|
7
|
+
DEFAULT_AUTOCOMPLETE_CONTENT_OPTS,
|
|
8
|
+
} from './autocomplete.js'
|
|
9
|
+
import { comboboxes } from './combobox-store.js'
|
|
10
|
+
|
|
11
|
+
let klass = ''
|
|
12
|
+
export { klass as class }
|
|
13
|
+
export let id
|
|
14
|
+
export let options = {}
|
|
15
|
+
|
|
16
|
+
const opts = {
|
|
17
|
+
...DEFAULT_AUTOCOMPLETE_CONTENT_OPTS.disclosure,
|
|
18
|
+
...DEFAULT_AUTOCOMPLETE_CONTENT_OPTS.floating,
|
|
19
|
+
...DEFAULT_AUTOCOMPLETE_CONTENT_OPTS.options,
|
|
20
|
+
...options,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { picked: comboboxOpts } = splitObject(opts, AUTOCOMPLETE_CONTENT_KEYS)
|
|
24
|
+
|
|
25
|
+
const listboxId = id + '-autocomplete'
|
|
26
|
+
let Box
|
|
27
|
+
let matches = []
|
|
28
|
+
let searchState = ''
|
|
29
|
+
|
|
30
|
+
$: Box = $comboboxes.find(c => c.id === listboxId)
|
|
31
|
+
$: if (Box) {
|
|
32
|
+
matches = Box.state.matches
|
|
33
|
+
searchState = Box.state.searchState
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<PopoverContent
|
|
38
|
+
{id}
|
|
39
|
+
class="AutocompleteOptions ListboxPopover {klass}"
|
|
40
|
+
options={opts}
|
|
41
|
+
>
|
|
42
|
+
{#if matches.length && searchState !== 'searching'}
|
|
43
|
+
<ul
|
|
44
|
+
id={listboxId}
|
|
45
|
+
tabindex="0"
|
|
46
|
+
class="Listbox Card-list {klass}"
|
|
47
|
+
role="listbox"
|
|
48
|
+
use:autocompleteOptions={{ options: comboboxOpts }}
|
|
49
|
+
>
|
|
50
|
+
<slot>
|
|
51
|
+
{#each matches as match}
|
|
52
|
+
<li role="option" aria-selected="false">
|
|
53
|
+
{#if Box.options.filterByProp}
|
|
54
|
+
{@html match.string}
|
|
55
|
+
{:else}
|
|
56
|
+
{@html match}
|
|
57
|
+
{/if}
|
|
58
|
+
</li>
|
|
59
|
+
{/each}
|
|
60
|
+
</slot>
|
|
61
|
+
</ul>
|
|
62
|
+
{/if}
|
|
63
|
+
|
|
64
|
+
{#if searchState === 'searching'}
|
|
65
|
+
<div class="Card AutocompleteLoader">
|
|
66
|
+
<slot name="loading">Loading...</slot>
|
|
67
|
+
</div>
|
|
68
|
+
{/if}
|
|
69
|
+
|
|
70
|
+
<!-- No results found. Optional -->
|
|
71
|
+
{#if searchState === 'complete' && matches.length === 0}
|
|
72
|
+
<div class="Card AutocompleteEmpty"><slot name="no-results"></slot></div>
|
|
73
|
+
{/if}
|
|
74
|
+
</PopoverContent>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import {
|
|
4
|
+
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
5
|
+
disclosureTrigger,
|
|
6
|
+
} from '../../Disclosure/disclosure.js'
|
|
7
|
+
import Hidden from '../Hidden.svelte'
|
|
8
|
+
import TextInput from '../TextInput.svelte'
|
|
9
|
+
import { comboboxes } from './combobox-store.js'
|
|
10
|
+
import {
|
|
11
|
+
COMBOBOX_INPUT_OPTION_KEYS,
|
|
12
|
+
comboboxAssociatedInput,
|
|
13
|
+
comboboxInput,
|
|
14
|
+
DEFAULT_COMBOBOX_INPUT_OPTIONS,
|
|
15
|
+
} from './combobox.js'
|
|
16
|
+
|
|
17
|
+
let klass = ''
|
|
18
|
+
export { klass as class }
|
|
19
|
+
export let name // name for the timepicker
|
|
20
|
+
export let target
|
|
21
|
+
export let options = {}
|
|
22
|
+
|
|
23
|
+
const opts = {
|
|
24
|
+
...DEFAULT_COMBOBOX_INPUT_OPTIONS.disclosure,
|
|
25
|
+
...DEFAULT_COMBOBOX_INPUT_OPTIONS.input,
|
|
26
|
+
options,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { picked: disclosureOpts } = splitObject(
|
|
30
|
+
opts,
|
|
31
|
+
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const { picked: comboboxInputOpts } = splitObject(
|
|
35
|
+
opts,
|
|
36
|
+
COMBOBOX_INPUT_OPTION_KEYS,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const listboxId = target + '-timepicker'
|
|
40
|
+
let inputRef
|
|
41
|
+
let hiddenRef
|
|
42
|
+
|
|
43
|
+
let Box
|
|
44
|
+
$: Box = $comboboxes.find(c => c.id === listboxId)
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<!-- This is what gets submitted -->
|
|
48
|
+
<Hidden
|
|
49
|
+
{name}
|
|
50
|
+
label="To be sent"
|
|
51
|
+
listbox-id={listboxId}
|
|
52
|
+
bind:ref={hiddenRef}
|
|
53
|
+
actions={[comboboxAssociatedInput]}
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
<!-- We cannot use type="time" because the appearance cannot be hijacked. To compensate, we added a hidden field that submits what an actual time input would submit. This TextInput is to give the appearance of a time input -->
|
|
57
|
+
<TextInput
|
|
58
|
+
type="text"
|
|
59
|
+
class="TimepickerInput {klass}"
|
|
60
|
+
name={name + '-displayed'}
|
|
61
|
+
{target}
|
|
62
|
+
bind:ref={inputRef}
|
|
63
|
+
listbox-id={listboxId}
|
|
64
|
+
aria-activedescendant={Box?.state.activeDescendantId || null}
|
|
65
|
+
actions={[
|
|
66
|
+
[disclosureTrigger, { options: disclosureOpts }],
|
|
67
|
+
[
|
|
68
|
+
comboboxInput,
|
|
69
|
+
{ options: comboboxInputOpts, nodes: { submittedField: hiddenRef } },
|
|
70
|
+
],
|
|
71
|
+
]}
|
|
72
|
+
{...$$restProps}
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<!-- Meh? How to include the button thingy? -->
|
|
76
|
+
|
|
77
|
+
<!-- Next steps:
|
|
78
|
+
1. Accessibility check for listbox -> short of activedescendant
|
|
79
|
+
2. Detailed / Segmented mode
|
|
80
|
+
3. Accessibility check for segmented mode
|
|
81
|
+
-->
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import PopoverContent from '../../Disclosure/Popover/PopoverContent.svelte'
|
|
4
|
+
import Checkboxes from '../Checkboxes.svelte'
|
|
5
|
+
import Radios from '../Radios.svelte'
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_LISTBOX_OPTIONS,
|
|
8
|
+
listbox,
|
|
9
|
+
LISTBOX_OPTION_KEYS,
|
|
10
|
+
} from './combobox'
|
|
11
|
+
import {
|
|
12
|
+
DEFAULT_TIMEPICKER_OPTIONS,
|
|
13
|
+
detailedTimepicker,
|
|
14
|
+
generateTimings,
|
|
15
|
+
} from './timepicker'
|
|
16
|
+
|
|
17
|
+
let klass = ''
|
|
18
|
+
export { klass as class }
|
|
19
|
+
export let id
|
|
20
|
+
export let options = {}
|
|
21
|
+
|
|
22
|
+
const opts = {
|
|
23
|
+
...DEFAULT_TIMEPICKER_OPTIONS,
|
|
24
|
+
...DEFAULT_LISTBOX_OPTIONS.disclosure,
|
|
25
|
+
...DEFAULT_LISTBOX_OPTIONS.floating,
|
|
26
|
+
...DEFAULT_LISTBOX_OPTIONS.options,
|
|
27
|
+
...options,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { picked: listboxOptions } = splitObject(opts, LISTBOX_OPTION_KEYS)
|
|
31
|
+
|
|
32
|
+
const listboxId = id + '-timepicker'
|
|
33
|
+
const { mode, selection } = opts
|
|
34
|
+
|
|
35
|
+
const timings = generateTimings(opts).map(timing => ({
|
|
36
|
+
name: `time-${timing.minutes}`, // for checkbox only
|
|
37
|
+
label: timing.timeString,
|
|
38
|
+
value: timing.timeString24H,
|
|
39
|
+
checked: false,
|
|
40
|
+
disabled: timing.blocked,
|
|
41
|
+
}))
|
|
42
|
+
|
|
43
|
+
// console.log(timings)
|
|
44
|
+
const showHours = opts.format.includes('HH')
|
|
45
|
+
const showMinutes = opts.format.includes('mm')
|
|
46
|
+
const showSeconds = opts.format.includes('ss')
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<PopoverContent
|
|
50
|
+
{id}
|
|
51
|
+
options={opts}
|
|
52
|
+
class="TimepickerOptions ListboxPopover {klass}"
|
|
53
|
+
>
|
|
54
|
+
{#if mode === 'list' && selection === 'single'}
|
|
55
|
+
<!-- This doesn't close the popover yet -->
|
|
56
|
+
<!-- Need some action to determine when to close the popover -->
|
|
57
|
+
<Radios
|
|
58
|
+
class="Timepicker {klass}"
|
|
59
|
+
legend="Time"
|
|
60
|
+
name="time"
|
|
61
|
+
radios={timings}
|
|
62
|
+
></Radios>
|
|
63
|
+
{/if}
|
|
64
|
+
|
|
65
|
+
{#if mode === 'list' && selection === 'multiple'}
|
|
66
|
+
<!-- This doesn't close the popover yet -->
|
|
67
|
+
<Checkboxes class="Timepicker {klass}" legend="Time" checkboxes={timings}
|
|
68
|
+
></Checkboxes>
|
|
69
|
+
{/if}
|
|
70
|
+
|
|
71
|
+
{#if mode === 'listbox'}
|
|
72
|
+
<ul
|
|
73
|
+
id={listboxId}
|
|
74
|
+
class="Listbox Card-list"
|
|
75
|
+
use:listbox={{ options: listboxOptions }}
|
|
76
|
+
>
|
|
77
|
+
{#each timings as timing}
|
|
78
|
+
<li data-value={timing.value}>
|
|
79
|
+
{timing.label}
|
|
80
|
+
</li>
|
|
81
|
+
{/each}
|
|
82
|
+
</ul>
|
|
83
|
+
{/if}
|
|
84
|
+
|
|
85
|
+
{#if mode === 'detailed'}
|
|
86
|
+
<ul id={listboxId} class="Listbox" use:detailedTimepicker>
|
|
87
|
+
{#if showHours}
|
|
88
|
+
<ul class="Card-list"></ul>
|
|
89
|
+
{/if}
|
|
90
|
+
|
|
91
|
+
{#if showMinutes}
|
|
92
|
+
<ul class="Card-list"></ul>
|
|
93
|
+
{/if}
|
|
94
|
+
|
|
95
|
+
{#if showSeconds}
|
|
96
|
+
<ul class="Card-list"></ul>
|
|
97
|
+
{/if}
|
|
98
|
+
</ul>
|
|
99
|
+
{/if}
|
|
100
|
+
</PopoverContent>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getNestedProperty2, mix } from '@splendidlabz/utils'
|
|
2
|
+
|
|
3
|
+
import aMatch from 'autosuggest-highlight/match'
|
|
4
|
+
import aParse from 'autosuggest-highlight/parse'
|
|
5
|
+
|
|
6
|
+
// Autosuggest highlight options can be found here:
|
|
7
|
+
// https://github.com/moroshko/autosuggest-highlight
|
|
8
|
+
const defaultSuggestOptions = {
|
|
9
|
+
insideWords: true,
|
|
10
|
+
requireMatchAll: true,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getMatches(strings, query, options = {}) {
|
|
14
|
+
// Two rounds of filtering for best results
|
|
15
|
+
const set = new Set([
|
|
16
|
+
...strings.filter(str =>
|
|
17
|
+
isMatch(str, query, { ...options, insideWords: false }),
|
|
18
|
+
),
|
|
19
|
+
|
|
20
|
+
// Filter through the matches
|
|
21
|
+
...strings.filter(str =>
|
|
22
|
+
isMatch(str, query, { ...options, insideWords: true }),
|
|
23
|
+
),
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
const uniques = Array.from(set)
|
|
27
|
+
|
|
28
|
+
return uniques.map(str => {
|
|
29
|
+
const m = _getMatch(str, query, options)
|
|
30
|
+
return _getHighlight(str, m)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getPropertyMatches({ items, prop, query, options = {} }) {
|
|
35
|
+
// Map objects for easier filtering
|
|
36
|
+
const objs = items.map(obj => {
|
|
37
|
+
const _str = getNestedProperty2(obj, prop)
|
|
38
|
+
if (!_str) throw new Error(`Property "${prop}" not found in object`)
|
|
39
|
+
return {
|
|
40
|
+
...obj,
|
|
41
|
+
_str: getNestedProperty2(obj, prop),
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Two rounds of filtering for best results
|
|
46
|
+
const set = new Set([
|
|
47
|
+
...objs.filter(obj => {
|
|
48
|
+
return isMatch(obj._str, query, { ...options, insideWords: false })
|
|
49
|
+
}),
|
|
50
|
+
...objs.filter(obj => {
|
|
51
|
+
return isMatch(obj._str, query, { ...options, insideWords: true })
|
|
52
|
+
}),
|
|
53
|
+
])
|
|
54
|
+
|
|
55
|
+
const uniques = Array.from(set)
|
|
56
|
+
|
|
57
|
+
return uniques.map(obj => {
|
|
58
|
+
const { _str, ...rest } = obj
|
|
59
|
+
const m = _getMatch(_str, query, options, { insideWords: true })
|
|
60
|
+
return {
|
|
61
|
+
...rest,
|
|
62
|
+
string: _getHighlight(_str, m),
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function hasPerfectMatch(strings, query) {
|
|
68
|
+
return strings.some(str => isPerfectMatch(str, query))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function hasPerfectPropertyMatch({ items, prop, query }) {
|
|
72
|
+
return items.some(obj => {
|
|
73
|
+
const str = getNestedProperty2(obj, prop)
|
|
74
|
+
return isPerfectMatch(str, query)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Returns list of matches
|
|
79
|
+
function _getMatch(string, query, options = {}) {
|
|
80
|
+
const opts = mix({}, defaultSuggestOptions, options)
|
|
81
|
+
return aMatch(string, query, opts)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function isMatch(string, query, options) {
|
|
85
|
+
return _getMatch(string, query, options).length > 0
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Either query or string my have diatrics
|
|
89
|
+
// So we need to pass them through _getMatch to ensure diatrics are handled in the matching.
|
|
90
|
+
function isPerfectMatch(string, query) {
|
|
91
|
+
const matches = _getMatch(string, query)
|
|
92
|
+
if (matches.length <= 0) return false // No match automatically means no perfect match
|
|
93
|
+
|
|
94
|
+
// Naïve checking for perfect match with a couple of assumptions
|
|
95
|
+
const firstIndex = matches[0][0]
|
|
96
|
+
const lastIndex = matches[matches.length - 1][1]
|
|
97
|
+
return (
|
|
98
|
+
firstIndex === 0 &&
|
|
99
|
+
lastIndex === string.length &&
|
|
100
|
+
string.length === query.length
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Parses and highlights the matched string
|
|
105
|
+
function _getHighlight(string, matches) {
|
|
106
|
+
const parts = aParse(string, matches)
|
|
107
|
+
return parts
|
|
108
|
+
.map(part => {
|
|
109
|
+
if (part.highlight)
|
|
110
|
+
return `<span class="ComboboxMatchedString">${part.text}</span>`
|
|
111
|
+
return part.text
|
|
112
|
+
})
|
|
113
|
+
.join('')
|
|
114
|
+
}
|