@txstate-mws/svelte-components 0.0.66 → 1.0.2

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.
Files changed (61) hide show
  1. package/README.md +12 -0
  2. package/dist/actions/{a11y.js → buttonify.js} +1 -1
  3. package/dist/actions/buttonify.js.map +1 -0
  4. package/dist/actions/glue.js +1 -3
  5. package/dist/actions/glue.js.map +1 -1
  6. package/dist/actions/index.js +1 -1
  7. package/dist/actions/index.js.map +1 -1
  8. package/dist/actions/portal.js +3 -7
  9. package/dist/actions/portal.js.map +1 -1
  10. package/dist/actions/stickyfixed.js +5 -5
  11. package/dist/components/CollapsingTable.svelte +3 -3
  12. package/dist/components/ConditionalWrapper.svelte +1 -1
  13. package/dist/components/FocusLock.svelte +13 -11
  14. package/dist/components/Modal.svelte +19 -11
  15. package/dist/components/PopupMenu.svelte +19 -18
  16. package/dist/components/ScreenReaderOnly.svelte +4 -5
  17. package/dist/lib/activestore.js +123 -0
  18. package/dist/lib/activestore.js.map +1 -0
  19. package/dist/lib/convertedstore.js +41 -0
  20. package/dist/lib/convertedstore.js.map +1 -0
  21. package/dist/lib/derivedstore.js +37 -25
  22. package/dist/lib/derivedstore.js.map +1 -1
  23. package/dist/lib/index.js +3 -1
  24. package/dist/lib/index.js.map +1 -1
  25. package/dist/lib/safestore.js +2 -2
  26. package/dist/lib/safestore.js.map +1 -1
  27. package/dist/lib/store.js +27 -0
  28. package/dist/lib/store.js.map +1 -0
  29. package/dist/lib/substore.js +10 -9
  30. package/dist/lib/substore.js.map +1 -1
  31. package/dist/ts/actions/{a11y.d.ts → buttonify.d.ts} +0 -0
  32. package/dist/ts/actions/glue.d.ts +1 -1
  33. package/dist/ts/actions/index.d.ts +1 -1
  34. package/dist/ts/actions/stickyfixed.d.ts +5 -5
  35. package/dist/ts/components/CollapsingTable.svelte +3 -3
  36. package/dist/ts/components/ConditionalWrapper.svelte +1 -1
  37. package/dist/ts/components/FocusLock.svelte +13 -10
  38. package/dist/ts/components/Modal.svelte +20 -11
  39. package/dist/ts/components/PopupMenu.svelte +18 -17
  40. package/dist/ts/components/ScreenReaderOnly.svelte +5 -5
  41. package/dist/ts/lib/activestore.d.ts +60 -0
  42. package/dist/ts/lib/convertedstore.d.ts +16 -0
  43. package/dist/ts/lib/derivedstore.d.ts +15 -8
  44. package/dist/ts/lib/index.d.ts +3 -1
  45. package/dist/ts/lib/safestore.d.ts +2 -2
  46. package/dist/ts/lib/store.d.ts +16 -0
  47. package/dist/ts/lib/substore.d.ts +7 -6
  48. package/dist/ts/tests/Modal/ModalTest.svelte +2 -2
  49. package/dist/ts/tests/PopupMenu/PopupMenuSimple.svelte +8 -2
  50. package/docs/CollapsingTable.md +11 -12
  51. package/docs/ConditionalWrapper.md +35 -0
  52. package/docs/Modal.md +63 -0
  53. package/docs/PopupMenu.md +31 -0
  54. package/docs/ScreenReaderOnly.md +10 -0
  55. package/docs/actions.md +76 -2
  56. package/docs/stores.md +203 -0
  57. package/package.json +17 -9
  58. package/dist/actions/a11y.js.map +0 -1
  59. package/dist/lib/deepstore.js +0 -80
  60. package/dist/lib/deepstore.js.map +0 -1
  61. package/dist/ts/lib/deepstore.d.ts +0 -42
@@ -1,16 +1,23 @@
1
- import { DeepStore, UsableSubject } from './deepstore';
1
+ import { Store } from './store';
2
+ import { UsableSubject } from './activestore';
3
+ export interface DerivedStoreOptions {
4
+ debounce?: number | boolean;
5
+ }
2
6
  /**
3
7
  * Watch one or more parent stores for changes. Each time, run a function to derive
4
8
  * a new state from the parent state(s). Subscribers will only be notified if the
5
9
  * derived state has changed (uses fast-deep-equal).
6
10
  *
7
11
  * If only one parent store, it's possible to use a dot-prop string as the getter.
8
- *
9
- * If you create one of these in a component, be sure to call .complete() in onDestroy
10
- * to free up memory.
11
12
  */
12
- export declare class DerivedStore<DerivedType, ParentType = any> extends DeepStore<DerivedType> {
13
- constructor(store: UsableSubject<ParentType>, getter: (value: ParentType) => DerivedType);
14
- constructor(store: UsableSubject<ParentType>, getter: string);
15
- constructor(store: UsableSubject<any>[], getter: (value: any[]) => DerivedType);
13
+ export declare class DerivedStore<DerivedType, ParentType = any> extends Store<DerivedType> {
14
+ constructor(store: UsableSubject<ParentType> | UsableSubject<any>[], getter: string | ((value: any) => DerivedType) | ((values: any[]) => DerivedType), options?: DerivedStoreOptions);
16
15
  }
16
+ export declare function derivedStore<DerivedType, ParentType, A extends keyof ParentType>(store: UsableSubject<ParentType>, accessor: A, options?: DerivedStoreOptions): DerivedStore<ParentType[A], ParentType>;
17
+ export declare function derivedStore<DerivedType, ParentType = any>(store: UsableSubject<ParentType>, accessor: string, options?: DerivedStoreOptions): DerivedStore<DerivedType, ParentType>;
18
+ export declare function derivedStore<DerivedType, ParentType>(store: UsableSubject<ParentType>, getter: (value: ParentType) => DerivedType, options?: DerivedStoreOptions): DerivedStore<DerivedType, ParentType>;
19
+ export declare function derivedStore<DerivedType, T1, T2>(store: [UsableSubject<T1>, UsableSubject<T2>], getter: (value: [T1, T2]) => DerivedType, options?: DerivedStoreOptions): DerivedStore<DerivedType>;
20
+ export declare function derivedStore<DerivedType, T1, T2, T3>(store: [UsableSubject<T1>, UsableSubject<T2>, UsableSubject<T3>], getter: (value: [T1, T2, T3]) => DerivedType, options?: DerivedStoreOptions): DerivedStore<DerivedType>;
21
+ export declare function derivedStore<DerivedType, T1, T2, T3, T4>(store: [UsableSubject<T1>, UsableSubject<T2>, UsableSubject<T3>, UsableSubject<T4>], getter: (value: [T1, T2, T3, T4]) => DerivedType, options?: DerivedStoreOptions): DerivedStore<DerivedType>;
22
+ export declare function derivedStore<DerivedType, T1, T2, T3, T4, T5>(store: [UsableSubject<T1>, UsableSubject<T2>, UsableSubject<T3>, UsableSubject<T4>, UsableSubject<T5>], getter: (value: [T1, T2, T3, T4, T5]) => DerivedType, options?: DerivedStoreOptions): DerivedStore<DerivedType>;
23
+ export declare function derivedStore<DerivedType>(store: UsableSubject<any>[], getter: (value: any[]) => DerivedType, options?: DerivedStoreOptions): DerivedStore<DerivedType>;
@@ -1,7 +1,9 @@
1
1
  export * from './bodyoffset';
2
- export * from './deepstore';
2
+ export * from './convertedstore';
3
3
  export * from './derivedstore';
4
+ export * from './activestore';
4
5
  export * from './repositioned';
5
6
  export * from './safestore';
7
+ export * from './store';
6
8
  export * from './substore';
7
9
  export * from './util';
@@ -1,4 +1,4 @@
1
- import { DeepStore } from './deepstore';
2
- export declare class SafeStore<T> extends DeepStore<T> {
1
+ import { Store } from './store';
2
+ export declare class SafeStore<T> extends Store<T> {
3
3
  clone(value: T): T;
4
4
  }
@@ -0,0 +1,16 @@
1
+ import { ActiveStore } from './activestore';
2
+ /**
3
+ * An alternative to svelte's "writable" that also checks deep equality (fast-deep-equal) before
4
+ * notifying subscribers. A writable will notify subscribers after a shallow equality check, which
5
+ * only works for scalars.
6
+ *
7
+ * Note that this strategy is weak against mutable state updates:
8
+ * store.update(v => { v.someprop = 'newvalue'; return v })
9
+ *
10
+ * This line would NOT notify subscribers because the state will be compared against
11
+ * itself and always found to be equal. If you are making updates in a mutable fashion,
12
+ * use a SafeStore instead.
13
+ */
14
+ export declare class Store<T> extends ActiveStore<T> {
15
+ equal(a: T, b: T): boolean;
16
+ }
@@ -1,4 +1,5 @@
1
- import { DeepStore, WritableSubject } from './deepstore';
1
+ import { Store } from './store';
2
+ import { WritableSubject } from './activestore';
2
3
  /**
3
4
  * Create a store that represents a part of a larger store. Updates to the parent store will propagate
4
5
  * down to the SubStore as appropriate, and updates to the SubStore will propagate
@@ -10,14 +11,14 @@ import { DeepStore, WritableSubject } from './deepstore';
10
11
  * generated. For example, a parent store containing state { deep: { value: 'here' }, hello: 'world' }
11
12
  * could be used with the getter string "deep.value". The SubStore's initial state would be "here", and
12
13
  * updating it to "there" would update the parent store state to { deep: { value: 'there' }, hello: 'world' }
13
- *
14
- * If you create one of these in a component, be sure to call .complete() in onDestroy to free up memory.
15
14
  */
16
- export declare class SubStore<SubType, ParentType = any> extends DeepStore<SubType> {
15
+ export declare class SubStore<SubType, ParentType = any> extends Store<SubType> {
17
16
  protected parentStore: WritableSubject<ParentType>;
18
17
  protected setter: (value: SubType, state: ParentType) => ParentType;
19
- constructor(store: WritableSubject<ParentType>, getter: string);
20
- constructor(store: WritableSubject<ParentType>, getter: (value: ParentType) => SubType, setter: (value: SubType, state: ParentType) => ParentType);
18
+ constructor(store: WritableSubject<ParentType>, getter: keyof ParentType | string | ((value: ParentType) => SubType), setter?: (value: SubType, state: ParentType) => ParentType);
21
19
  set(value: SubType): void;
22
20
  clone(state: SubType): any;
23
21
  }
22
+ export declare function subStore<SubType, ParentType, A extends keyof ParentType>(store: WritableSubject<ParentType>, accessor: A): SubStore<ParentType[A], ParentType>;
23
+ export declare function subStore<SubType, ParentType = any>(store: WritableSubject<ParentType>, accessor: string): SubStore<SubType, ParentType>;
24
+ export declare function subStore<SubType, ParentType>(store: WritableSubject<ParentType>, getter: (value: ParentType) => SubType, setter: (value: SubType, state: ParentType) => ParentType): SubStore<SubType, ParentType>;
@@ -4,7 +4,7 @@
4
4
  </script>
5
5
 
6
6
  {#if shown}
7
- <Modal initialfocus='input[type="submit"]' on:dismiss={() => shown = false}>
7
+ <Modal on:escape={() => shown = false}>
8
8
  <form>
9
9
  <div class="formfield">
10
10
  <label for="firstname">First Name:</label><input id="firstname" type="text" name="firstname">
@@ -23,7 +23,7 @@
23
23
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer tempus nulla ut nulla auctor, quis sodales massa laoreet. Duis erat lacus, gravida vitae massa vel, semper accumsan urna. Morbi gravida dui sit amet sodales luctus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum eget pulvinar dui. Vivamus quis eros eu ex semper consectetur nec at elit. Praesent faucibus arcu a nisi semper, eu tempus felis vehicula. Suspendisse potenti.</p>
24
24
 
25
25
  <p>Donec luctus nulla mattis ipsum aliquam imperdiet. Vestibulum nec finibus enim. Proin et arcu arcu. Quisque feugiat leo velit, vitae mollis felis ornare sed. Suspendisse sollicitudin, libero sed ullamcorper finibus, diam turpis eleifend velit, ut suscipit orci mauris id purus. Donec dapibus facilisis mauris a venenatis. Maecenas gravida velit maximus nibh tincidunt, eget auctor tellus efficitur. Aenean varius tristique lacus, sit amet placerat sem tempor at. Sed imperdiet fermentum nibh, sit amet tempor est cursus ac.</p>
26
- <button on:click={() => shown = true}>Show Modal</button>
26
+ <button data-testid="button" on:click={() => shown = true}>Show Modal</button>
27
27
  <p>Praesent augue magna, maximus at mattis eget, euismod nec neque. Phasellus ut dolor a turpis molestie fermentum. Phasellus condimentum, ipsum sed rutrum maximus, diam ex ultrices sapien, quis iaculis nisi arcu at turpis. Morbi aliquam mattis posuere. Integer pretium diam diam, non lobortis quam consectetur laoreet. Sed posuere blandit venenatis. Nulla gravida maximus arcu non consectetur.</p>
28
28
 
29
29
  <p>Cras egestas massa mattis dictum imperdiet. Nulla bibendum nisl ipsum, ut scelerisque arcu consectetur vitae. Integer convallis id nunc sit amet faucibus. Maecenas suscipit diam orci, ac suscipit dolor convallis sed. Mauris vel tellus eget nunc mattis faucibus sit amet sed lorem. Cras lobortis, massa at vestibulum dignissim, quam tellus sagittis purus, eget dictum dolor quam in leo. Aliquam condimentum, ante sit amet semper laoreet, lacus est scelerisque mi, nec mollis diam massa et massa. Donec sagittis massa quis diam dictum, sit amet convallis mauris tincidunt. Nam vulputate ligula quis ex condimentum, in sollicitudin dolor accumsan. Donec volutpat dui in faucibus tempus. Proin vitae tincidunt ex. Proin ut ultricies diam. Praesent sed purus in purus efficitur fermentum vulputate quis dolor. Morbi viverra quam ac dolor facilisis consectetur.</p>
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
+ import { hashify } from 'txstate-utils'
2
3
  import PopupMenu from '../../components/PopupMenu.svelte'
3
- let button: HTMLElement
4
4
 
5
5
  export let showSelected = false
6
6
  export let items = [
@@ -12,12 +12,18 @@
12
12
  { value: '5', label: 'Friday' },
13
13
  { value: '6', label: 'Saturday', disabled: true }
14
14
  ]
15
+
16
+ let button: HTMLElement
17
+ let value: string
18
+ $: itemsByValue = hashify(items, 'value')
19
+ $: selected = itemsByValue[value]
15
20
  </script>
16
21
 
17
22
  <div class="topspacer"></div>
18
23
  <div class="container">
19
24
  <button data-testid="button" class="ui gold button" bind:this={button}>Popup Menu</button>
20
- <PopupMenu buttonelement={button} {items} {showSelected}></PopupMenu>
25
+ <div>selected: {#if selected}{selected.value}, {selected.label}{:else}none{/if}</div>
26
+ <PopupMenu bind:value buttonelement={button} {items} {showSelected}></PopupMenu>
21
27
  </div>
22
28
 
23
29
  <style>
@@ -21,12 +21,7 @@ A `config` prop allows you to pass an array of column definitions. If passed, on
21
21
  the column that is most identifying for each row, like a name.
22
22
  by default the leftmost column will stick around as identifying
23
23
  * `bodyCellClass?: string` CSS class to set on `td` elements in the body area
24
- `item`, `key`, and `value` as props. The value will also be placed inside your component's
25
- default slot as a bare string.
26
24
  * `headerCellClass?: string` CSS class to set on `td` elements in the header row
27
- `column`, `key`, and `title` as props, where `column` is this configuration object, and `title`
28
- is reliable (uses `key` if configuration had no `title`). The title/key will also be placed
29
- inside your component's default slot as a bare string.
30
25
 
31
26
  ## Optional Props
32
27
  * `tableClass` CSS class for the `table`
@@ -43,12 +38,12 @@ A `config` prop allows you to pass an array of column definitions. If passed, on
43
38
  Lots of slots are provided for extra configuration.
44
39
 
45
40
  ### Default Slot
46
- The default slot is used for each table cell in the body area. Because of the way slots work, your
47
- content will always be executed in every cell. So if you need to do something special for just one
48
- cell, you have to use an if/else block to identify the special cell, falling back to {value} for
49
- everything else:
41
+ The default slot is used for each table cell in the body area. It is optional and falls back to {value}.
42
+ Because of the way slots work, your slot content will be executed in every cell. So if you need to do
43
+ something special for just one cell, you have to use an if/else block to identify the special cell,
44
+ falling back to {value} for everything else:
50
45
  ```svelte
51
- <CollapsingTable items={myItems} let:key let:value>
46
+ <CollapsingTable items={myItems} let:item let:key let:value>
52
47
  {#if key === 'myspecialkey'}
53
48
  <MySpecialComponent>{value}</MySpecialComponent>
54
49
  {:else}
@@ -56,11 +51,12 @@ everything else:
56
51
  {/if}
57
52
  </CollapsingTable>
58
53
  ```
54
+ The slot props are `item`, `key`, and `value`.
59
55
  ### Header Cell Slot
60
56
  A slot named `headercell` allows you to do the same thing for cells in the header row that the
61
57
  default slot allows for body cells.
62
58
  ```svelte
63
- <CollapsingTable items={myItems} let:key let:title>
59
+ <CollapsingTable items={myItems} let:column let:key let:title>
64
60
  <div slot="headercell">
65
61
  {#if key === 'myspecialkey'}
66
62
  <MySpecialComponent>{title}</MySpecialComponent>
@@ -70,11 +66,14 @@ default slot allows for body cells.
70
66
  </div>
71
67
  </CollapsingTable>
72
68
  ```
69
+ The slot props are `column`, `key`, and `title`. `column` is the configuration object for the
70
+ current column, `title` is `column.title || column.key`. The title/key will be used as fallback
71
+ content if you do not specify a header slot.
73
72
  ### Dropdown Icon Slot
74
73
  A slot is provided for you to provide a custom icon for the column header that is serving as the
75
74
  dropdown button.
76
75
  ```svelte
77
- <CollapsingTable items={myItems} let:key let:value>
76
+ <CollapsingTable items={myItems}>
78
77
  <i type='fa caret-down' slot="dropicon" aria-hidden="true"></i>
79
78
  </CollapsingTable>
80
79
  ```
@@ -0,0 +1,35 @@
1
+ # Conditional Wrapper
2
+ Sometimes you want to wrap a complex bit of HTML in a certain element based on a condition,
3
+ and not wrap it at all if the condition isn't met. Without help, this situation results in a
4
+ lot of duplicate code because you have to have an if/else block outside the whole thing, and
5
+ the complex HTML goes in both branches:
6
+ ```svelte
7
+ {#if shouldwrap}
8
+ <div class="wrapper">
9
+ ... a whole bunch of html ...
10
+ </div>
11
+ {:else}
12
+ ... a whole bunch of html, again ...
13
+ {/if}
14
+ ```
15
+ With this component, you can de-duplicate like this:
16
+ ```svelte
17
+ <ConditionalWrapper class="wrapper" condition={shouldwrap}>
18
+ ... a whole bunch of html ...
19
+ </ConditionalWrapper>
20
+ ```
21
+ Any props you provide (except the ConditionalWrapper props like `condition`) will pass through
22
+ to the wrapper element/component, if it gets inserted.
23
+
24
+ ## Props
25
+ * `condition: boolean|undefined` (required) - Whether or not to wrap the element. Accepts `undefined`
26
+ for convenience when evaluating presence of an optional variable.
27
+ * `component?: SvelteComponent` (optional) - The wrapper will be a svelte component instead of a DOM
28
+ element. Props all get passed through.
29
+ * `a: boolean` (optional) - The wrapper will be a link element.
30
+ * `span: boolean` (optional) - The wrapper will be a span element.
31
+ * `element?: HTMLElement` (for binding) - If the wrapper is a DOM element, bind this prop to get a
32
+ reference to wrapper element (if it exists). If the wrapper is a svelte component, this will be
33
+ passed to it as a prop so that the wrapper component can bind it to a DOM element.
34
+
35
+ If none of `a`, `span`, or `component` props are specified, the default is to create a `div` wrapper.
package/docs/Modal.md ADDED
@@ -0,0 +1,63 @@
1
+ # Modal
2
+ The Modal component is designed to block out the screen and focus the user on the content inside the Modal.
3
+
4
+ It provides only the backdrop and a scrollable container for your content. If your content should have a background color, be sure to add it yourself.
5
+
6
+ Any time the Modal is in the DOM, it will take over the screen. You make it go away by removing it from the DOM.
7
+
8
+ ## Example Usage
9
+ ```svelte
10
+ <script>
11
+ let showMyModal = false
12
+ </script>
13
+ <button on:click={() => showMyModal = true}>Show Modal</button>
14
+ {#if showMyModal}
15
+ <Modal on:escape={() => showMyModal = false}>
16
+ This is a modal dialog!
17
+ </Modal>
18
+ {/if}
19
+ <style>
20
+ :global(.modal-container) { background: white; }
21
+ </style>
22
+ ```
23
+ ## Custom Events
24
+ * `on:escape` - dispatched when the user does something that would normally dismiss a modal, such as clicking in the darkened backdrop or pressing the Escape key. You should listen for this and dismiss your modal. If you do not listen for this event, users will only be able to escape by some other means provided within your content. Be careful not to trap them!
25
+
26
+ ## Props
27
+ * `opaque: boolean` (default `false`) - Make the backdrop completely opaque so that it cannot be seen through. This is a more jarring experience for users but sometimes you don't want background content to be visible at all.
28
+ * `containerClass: string` (default `''`) - A class to be added to the scrollable container inside the backdrop. This container will always have the `.modal-container` class regardless of this prop.
29
+ * `escapable: boolean` (default `true`) - Let screen readers know that they can escape the modal by pressing the Escape key. If you are not listening for `on:escape` then you should set this `false` to avoid giving screen reader users false information.
30
+ * `hidefocus: boolean` (default `true`) - Focus must be moved to the modal when it opens, in order to maintain accessibility. This component avoids making the focus visible to users by default as it might be visually disconcerting. So on mount, focus is moved to an invisible element above your content. If you prefer focus to be visible to users, set this to `false` and focus will automatically be moved to the first element in your content that has a tabindex and therefore be visible to users. This prop is overridden if you provide an `initialfocus`.
31
+ * `hidefocuslabel: string` (default `focus is above modal dialog, start tabbing`) - The message that will be read out to users using a screen reader when the focus is on the invisible element created by the `hidefocus` prop.
32
+ * `initialfocus: string` (default `undefined`) - A selector to be used to locate and set focus on an element in your content, on mount. Use if you want focus on a specific element when the modal opens. Overrides `hidefocus`.
33
+ * `returnfocusto: HTMLElement` (default element that had focus was when modal opened) - Use to control where focus moves when the modal closes. If not provided, component automatically saves the element that had focus on mount. Usually it's the button that triggered the modal.
34
+
35
+ # FocusLock
36
+ The FocusLock component is for creating accessible modal dialogs that do not have a darkened backdrop. It shares many props and behaviors with Modal because the Modal component uses a FocusLock itself.
37
+
38
+ Any time the FocusLock is in the DOM, it will lock screen readers inside it. You release them by removing it from the DOM. Regular users are NOT trapped and may interact with other screen elements. When they do, the `escape` event will be fired, allowing you to remove the dialog.
39
+
40
+ FocusLocks can be nested. The user will be trapped inside the deepest FocusLock present in the DOM. When it goes away, they'll be trapped inside the previous FocusLock, and so on.
41
+
42
+ ## Custom Events
43
+ * `on:escape` - dispatched when the user does something to dismiss the dialog, such as pressing the Escape key or clicking outside the dialog area. You should listen for this and remove the FocusLock. If you do not listen for this event, users will only be able to escape by some other means provided within your content. Be careful not to trap them!
44
+
45
+ ## Example Usage
46
+ ```svelte
47
+ <script>
48
+ let showMyDialog = false
49
+ </script>
50
+ <button on:click={() => showMyDialog = true}>Show Dialog</button>
51
+ {#if showMyDialog}
52
+ <FocusLock on:escape={() => showMyDialog = false}>
53
+ Screen readers cannot escape this!
54
+ <button on:click={() => showMyDialog = false}>Collapse Dialog</button>
55
+ </FocusLock>
56
+ {/if}
57
+ ```
58
+ ## Props
59
+ * `escapable: boolean` (default `true`) - Controls whether the focus lock can be easily escaped by pressing the Escape key or clicking the invisible focus (see `hidefocus`). If you set this `false` you must provide a way to dismiss the lock inside your content or screen readers will be trapped.
60
+ * `hidefocus: boolean` (default `true`) - Focus must be moved to the modal when it opens, in order to maintain accessibility. This component avoids making the focus visible to users by default as it might be visually disconcerting. So on mount, focus is moved to an invisible element above your content. If you prefer focus to be visible to users, set this to `false` and focus will automatically be moved to the first element in your content that has a tabindex and therefore be visible to users. This prop is overridden if you provide an `initialfocus`.
61
+ * `hidefocuslabel: string` (default `focus is above modal dialog, start tabbing`) - The message that will be read out to users using a screen reader when the focus is on the invisible element created by the `hidefocus` prop.
62
+ * `initialfocus: string` (default `undefined`) - A selector to be used to locate and set focus on an element in your content, on mount. Use if you want focus on a specific element when the lock mounts. Overrides `hidefocus`.
63
+ * `returnfocusto: HTMLElement` (default element that had focus was when focuslock mounted) - Use to control where focus moves when the lock ends. If not provided, component automatically saves the element that had focus on mount. Usually it's the button that triggered the dialog.
@@ -0,0 +1,31 @@
1
+ # PopupMenu
2
+
3
+ This component is meant to display a menu of options to the user, activated by clicking
4
+ any element. It can also be controlled from the parent, by binding the `menushown` boolean.
5
+
6
+ ## Props
7
+ * `buttonelement: HTMLElement` (required) - The DOM element that will act as the "button" for this menu. The menu will be placed next to the button and be controlled by the button. Keyboard access will be enabled when the button has focus. This component adds all appropriate attributes (tabindex, roles, and aria) automatically.
8
+ * `items: PopupMenuItem[]` (required) - The list of menu items to be shown. Parent may change this at any time based on user activity.
9
+ * `menushown?: boolean` (default `false`) - Bind this prop to track/change the visible state of the menu from the parent.
10
+ * `value?: string` (default no selection) - Bind this prop to track/change the currently selected value from the parent.
11
+ * `align?: GlueAlignOpts` (default `auto`) - Control where the menu will appear. Default is to use the current viewport to make a decision to maximize potential for menu growth.
12
+ * `cover?: boolean` (default `false`) - When the menu is active, should it cover the button or be rendered above/below it?
13
+ * `showSelected?: boolean` (default `true`) - When an item is currently selected, should it appear in the menu (with a visual indicator), or simply be removed from the list (showSelected: `false`)?
14
+ * `width?: string` (default `undefined`) - When defined, this width will be passed through to the menu's CSS width. Use a valid CSS dimension such as `33em` or `159px`. Generally this will be used when you need to match the menu width to something else, like the button. If the width is static like `100%` a simple CSS rule is likely more efficient.
15
+ * `computedalign: readable<{ valign: 'top'|'bottom', halign: 'left'|'right' }>` (default store is provided) - Bind this prop to receive a store that is updated each time a menu placement decision is made. Example of when this is useful is when you are trying to round corners of your button and need to know whether the menu is above or below your button so you know which corners to round and which to leave square. Note that the values do not update when the menu is hidden, so you may need to rely on `menushown` as well.
16
+ * `usePortal?: HTMLElement|true` (default `false`) - If the menu would be clipped by an `overflow: hidden`, you can set this prop and it will be placed in the specified container, or the `document.body` if you simply say `true`. Placement will still be calculated correctly, unless there are scrolling containers between the button and the menu.
17
+ * `emptyText?: string` (default `¯\_(ツ)_/¯`) - When there are no items (e.g. it's a filtered search and there were no results), we still display one disabled item in the menu to let the user know what is going on. Use this prop to specify the message.
18
+ * `menuContainerClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
19
+ * `menuClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
20
+ * `menuItemClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
21
+ * `menuItemHilitedClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
22
+ * `menuItemSelectedClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
23
+
24
+ ## Events
25
+ * `on:change` - Dispatched any time a new value is selected. Does not fire when you change the `value` property from the outside. Event detail will be the full PopupMenuItem object that was selected.
26
+
27
+ ## Types
28
+ * `PopupMenuItem: { value: string, label?: string, disabled?: boolean }` - Each item must have a unique non-empty value. Display label is optional, as is a `disabled` status that will show the item in the list but not allow users to hilite or select it.
29
+
30
+ ## Disabling
31
+ Since there are so many different possibilities for the button you attach to, the PopupMenu does not have a `disabled` prop. If the PopupMenu should be disabled, simply remove it from the DOM with an `{#if}` block. Remember to also set `aria-disabled` on your button and likely provide some visual indicators like `cursor: default` or the `disabled` attribute on elements that support it.
@@ -0,0 +1,10 @@
1
+ # ScreenReaderOnly
2
+ This component is for adding text that can be read to screen readers while remaining
3
+ invisible to regular users. It accepts `arialive` and `ariaatomic` props to pass through to
4
+ the corresponding HTML attributes. It also accepts an `id` prop in case you need to
5
+ point at it with an aria-describedby attribute on some other element.
6
+
7
+ Using this component is often better than using aria-label because aria-label still has poor support
8
+ and sometimes is not good enough to make WAVE happy with an empty icon-link. It's also a
9
+ good way to add additional text when sighted users have a little text already, e.g. to add
10
+ interactivity instructions.
package/docs/actions.md CHANGED
@@ -1,10 +1,84 @@
1
1
  # Actions
2
2
 
3
+ ## use:buttonify
4
+ This action turns any HTML element into an accessible button that responds to keyboard events and has
5
+ role="button" and the tabindex attribute set. You are still responsible for making sure it has
6
+ readable content or a good label. Does NOT change styling at all.
7
+ ```svelte
8
+ <div use:buttonify on:click={onClick}>You can tab to me and click me with the Enter key</div>
9
+ ```
10
+
3
11
  ## use:glue
4
- This action glues the element it is placed on to the target specified, with a specified alignment option. The element is placed in document.body so that it cannot be constrained or hidden by overflow:hidden, then it is positioned to match the target element. It is most useful for dropdown or autocomplete menus.
12
+ This action glues the element it is placed on to the target specified, with a specified alignment
13
+ option. It is most useful for dropdown or autocomplete menus.
14
+
15
+ The element should have `position: absolute` on it already. It is not moved to a new place in the DOM,
16
+ it just gets `top`/`left`/`bottom`/`right` properties set.
17
+
18
+ If you have problems with the glued element being clipped by a parent with `overflow: hidden`, you
19
+ may combine it with the `use:portal` action to move it somewhere else; `use:glue` will recalculate
20
+ for the new location.
21
+
22
+ If you do not specify an `align` setting, the default is `auto`, which will evaluate the current
23
+ viewport and determine which alignment gives the glued element the most space to grow.
5
24
  ```svelte
6
25
  <button bind:this={menubutton}>Activate Menu</button>
7
- <ul use:glue={{ element: menubutton, align: 'bottomright' }}>
26
+ <ul use:glue={{ target: menubutton, align: 'bottomright' }}>
8
27
  <li>Menu Item 1</li>
9
28
  <li>Menu Item 2</li>
29
+ </ul>
30
+ ```
31
+
32
+ ## use:offset
33
+ This action allows you to observe any DOM element's position in the body. You pass in a svelte store
34
+ and it will be updated when the element moves.
35
+
36
+ Another configuration option is `debounce: number`, which will debounce the updates for the specified
37
+ number of milliseconds. Use this option if you will make a complicated calculation after each update and do not
38
+ want to perform the calculation multiple times during a single animation or while the user is resizing
39
+ their viewport/window. It will defer the updates until the animation or resizing stops for at least `debounce`
40
+ milliseconds.
41
+ ```svelte
42
+ <script>
43
+ const offset = writable({ top: 0, left: 0, bottom: 0, right: 0 })
44
+ </script>
45
+ <div use:offset={{ store: offset }}>distance between me and body top is {$offset.top}</div>
46
+ ```
47
+
48
+ ## use:portal
49
+ This action allows you to move an element to a new place in the DOM upon mount. It's useful when your component
50
+ is sensitive to getting clipped by parents with overflow: hidden or for anything like a modal or toast message
51
+ that needs to be positioned relative to the body, but created within a smaller component, like a web form.
52
+
53
+ For convenience, the default is to move it to `document.body` when you `use:portal` without any config:
54
+ ```svelte
55
+ <div use:portal>I'm in the body now!</div>
56
+ ```
57
+ If you are accepting an optional target as a prop, this may cause unexpected behavior where your parent component
58
+ declines to pass a portal target, but your element ends up in `document.body`. To prevent this, you may pass `null`
59
+ instead of `undefined`, and the element will stay where it was before the change to `null`:
60
+ ```svelte
61
+ <script>
62
+ export let portaltarget = undefined
63
+ </script>
64
+ <div use:portal={portaltarget || null}></div>
65
+ ```
66
+
67
+ ## use:resize
68
+ This action allows you to observe an element's width and height with the `ResizeObserver`. Svelte has a built-in
69
+ `bind:clientWidth` functionality, but it works by inserting an invisible iframe into the DOM for each observation,
70
+ which is a little ugly and potentially slow.
71
+
72
+ You pass in a svelte store and it will be updated when the element's size changes.
73
+
74
+ Another configuration option is `debounce: number`, which will debounce the updates for the specified
75
+ number of milliseconds. Use this option if you will make a complicated calculation after each update and do not
76
+ want to perform the calculation multiple times during a single animation or while the user is resizing
77
+ their viewport/window. It will defer the updates until the animation or resizing stops for at least `debounce`
78
+ milliseconds.
79
+ ```svelte
80
+ <script>
81
+ const size = writable({ clientWidth: 100, clientHeight: 100, offsetWidth: 100, offsetHeight: 100 })
82
+ </script>
83
+ <div use:offset={{ store: size }}>My dimensions are {$size.offsetWidth}x{$size.offsetHeight}</div>
10
84
  ```