@onsvisual/svelte-components 1.0.0-next.4 → 1.0.0-next.6
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/dist/datavis/DataTile/DataTile.stories.svelte +28 -0
- package/dist/datavis/DataTile/DataTile.stories.svelte.d.ts +23 -0
- package/dist/datavis/DataTile/DataTile.svelte +56 -0
- package/dist/datavis/DataTile/DataTile.svelte.d.ts +37 -0
- package/dist/datavis/DataTile/docs/component.md +17 -0
- package/dist/datavis/Table/Table.svelte +6 -0
- package/dist/datavis/Table/Table.svelte.d.ts +2 -0
- package/dist/decorators/Divider/Divider.svelte +8 -3
- package/dist/decorators/Divider/Divider.svelte.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inputs/Button/Button.svelte +7 -2
- package/dist/inputs/Button/Button.svelte.d.ts +2 -0
- package/dist/inputs/Checkbox/Checkbox.svelte +48 -39
- package/dist/inputs/Checkbox/Checkbox.svelte.d.ts +8 -6
- package/dist/inputs/Checkboxes/Checkboxes.stories.svelte +7 -15
- package/dist/inputs/Checkboxes/Checkboxes.svelte +35 -11
- package/dist/inputs/Checkboxes/Checkboxes.svelte.d.ts +6 -0
- package/dist/inputs/Checkboxes/docs/component.md +1 -1
- package/dist/inputs/Dropdown/Dropdown.svelte +6 -1
- package/dist/inputs/Dropdown/Dropdown.svelte.d.ts +2 -0
- package/dist/inputs/ErrorPanel/ErrorPanel.svelte +6 -1
- package/dist/inputs/ErrorPanel/ErrorPanel.svelte.d.ts +2 -0
- package/dist/inputs/ErrorSummary/ErrorSummary.svelte +6 -1
- package/dist/inputs/ErrorSummary/ErrorSummary.svelte.d.ts +2 -0
- package/dist/inputs/Input/Input.svelte +6 -1
- package/dist/inputs/Input/Input.svelte.d.ts +2 -0
- package/dist/inputs/Radios/Radio.svelte +31 -22
- package/dist/inputs/Radios/Radio.svelte.d.ts +8 -6
- package/dist/inputs/Radios/Radios.svelte +35 -19
- package/dist/inputs/Radios/Radios.svelte.d.ts +8 -2
- package/dist/inputs/Radios/docs/component.md +2 -2
- package/dist/inputs/Select/Select.svelte +6 -1
- package/dist/inputs/Select/Select.svelte.d.ts +2 -0
- package/dist/inputs/Textarea/Textarea.svelte +6 -1
- package/dist/inputs/Textarea/Textarea.svelte.d.ts +2 -0
- package/dist/intro.mdx +9 -2
- package/dist/layout/Accordion/Accordion.svelte +1 -1
- package/dist/layout/Accordion/Accordion.svelte.d.ts +2 -2
- package/dist/layout/Breadcrumb/Breadcrumb.svelte +11 -1
- package/dist/layout/Breadcrumb/Breadcrumb.svelte.d.ts +4 -0
- package/dist/layout/Card/Card.svelte +1 -1
- package/dist/layout/Card/Card.svelte.d.ts +2 -2
- package/dist/layout/Contents/Contents.svelte +6 -1
- package/dist/layout/Contents/Contents.svelte.d.ts +2 -0
- package/dist/layout/DescriptionList/DescriptionList.svelte +6 -1
- package/dist/layout/DescriptionList/DescriptionList.svelte.d.ts +2 -0
- package/dist/layout/Details/Details.svelte +6 -1
- package/dist/layout/Details/Details.svelte.d.ts +2 -0
- package/dist/layout/DocumentList/DocumentList.svelte +6 -1
- package/dist/layout/DocumentList/DocumentList.svelte.d.ts +2 -0
- package/dist/layout/Footer/Footer.svelte +1 -1
- package/dist/layout/Footer/Footer.svelte.d.ts +4 -4
- package/dist/layout/Grid/Grid.svelte +3 -3
- package/dist/layout/Grid/Grid.svelte.d.ts +2 -2
- package/dist/layout/Header/Header.svelte +1 -1
- package/dist/layout/Header/Header.svelte.d.ts +4 -4
- package/dist/layout/Hero/Hero.stories.svelte +2 -1
- package/dist/layout/Hero/Hero.svelte +9 -8
- package/dist/layout/Hero/Hero.svelte.d.ts +8 -6
- package/dist/layout/Highlight/Highlight.svelte +15 -22
- package/dist/layout/Highlight/Highlight.svelte.d.ts +6 -6
- package/dist/layout/Image/Image.svelte +6 -1
- package/dist/layout/Image/Image.svelte.d.ts +2 -0
- package/dist/layout/List/List.svelte +6 -1
- package/dist/layout/List/List.svelte.d.ts +2 -0
- package/dist/layout/NavSections/NavSection.svelte +1 -1
- package/dist/layout/NavSections/NavSection.svelte.d.ts +2 -2
- package/dist/layout/NavSections/NavSections.svelte +3 -3
- package/dist/layout/NavSections/NavSections.svelte.d.ts +2 -2
- package/dist/layout/Notice/Notice.svelte +6 -1
- package/dist/layout/Notice/Notice.svelte.d.ts +2 -0
- package/dist/layout/PhaseBanner/PhaseBanner.svelte +6 -1
- package/dist/layout/PhaseBanner/PhaseBanner.svelte.d.ts +2 -0
- package/dist/layout/RelatedContent/RelatedContent.svelte +6 -1
- package/dist/layout/RelatedContent/RelatedContent.svelte.d.ts +2 -0
- package/dist/layout/Scroller/Scroller.svelte +6 -1
- package/dist/layout/Scroller/Scroller.svelte.d.ts +2 -0
- package/dist/layout/Scroller/ScrollerSection.svelte +6 -1
- package/dist/layout/Scroller/ScrollerSection.svelte.d.ts +2 -0
- package/dist/layout/Section/Section.svelte +3 -3
- package/dist/layout/Section/Section.svelte.d.ts +2 -2
- package/dist/layout/ShareButtons/ShareButtons.svelte +8 -3
- package/dist/layout/ShareButtons/ShareButtons.svelte.d.ts +2 -0
- package/dist/layout/Summary/Summary.svelte +6 -1
- package/dist/layout/Summary/Summary.svelte.d.ts +2 -0
- package/dist/layout/Tabs/Tabs.svelte +6 -1
- package/dist/layout/Tabs/Tabs.svelte.d.ts +2 -0
- package/dist/templates/intro.mdx +1 -1
- package/dist/wrappers/Container/Container.svelte +41 -28
- package/dist/wrappers/Container/Container.svelte.d.ts +8 -4
- package/dist/wrappers/Container/docs/component.md +4 -2
- package/dist/wrappers/Theme/Theme.svelte +4 -4
- package/dist/wrappers/Theme/Theme.svelte.d.ts +6 -6
- package/dist/wrappers/Theme/docs/component.md +1 -1
- package/dist/wrappers/Theme/themes.d.ts +28 -0
- package/dist/wrappers/Theme/themes.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
3
|
+
import { withComponentDocs } from "../../js/withParams.js";
|
|
4
|
+
import DataTile from "./DataTile.svelte";
|
|
5
|
+
import componentDocs from "./docs/component.md?raw";
|
|
6
|
+
|
|
7
|
+
const { Story } = defineMeta({
|
|
8
|
+
title: "Data visualisation/DataTile",
|
|
9
|
+
component: DataTile,
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
argTypes: {
|
|
12
|
+
mode: {
|
|
13
|
+
control: { type: "select" }
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
parameters: withComponentDocs(componentDocs)
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<Story
|
|
21
|
+
name="Big number"
|
|
22
|
+
args={{
|
|
23
|
+
title: "Consumer Price Index (CPI)",
|
|
24
|
+
value: "up 2.5%",
|
|
25
|
+
caption: "in 12 months to December 2024",
|
|
26
|
+
source: "Source: ONS"
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} DataTileProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} DataTileEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} DataTileSlots */
|
|
4
|
+
export default class DataTile extends SvelteComponentTyped<{
|
|
5
|
+
[x: string]: never;
|
|
6
|
+
}, {
|
|
7
|
+
[evt: string]: CustomEvent<any>;
|
|
8
|
+
}, {}> {
|
|
9
|
+
}
|
|
10
|
+
export type DataTileProps = typeof __propDef.props;
|
|
11
|
+
export type DataTileEvents = typeof __propDef.events;
|
|
12
|
+
export type DataTileSlots = typeof __propDef.slots;
|
|
13
|
+
import { SvelteComponentTyped } from "svelte";
|
|
14
|
+
declare const __propDef: {
|
|
15
|
+
props: {
|
|
16
|
+
[x: string]: never;
|
|
17
|
+
};
|
|
18
|
+
events: {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
};
|
|
21
|
+
slots: {};
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Card from "../../layout/Card/Card.svelte";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Title of card
|
|
6
|
+
* @type {string}
|
|
7
|
+
*/
|
|
8
|
+
export let title = "";
|
|
9
|
+
/**
|
|
10
|
+
* Optional: URL link for card title
|
|
11
|
+
* @type {string}
|
|
12
|
+
*/
|
|
13
|
+
export let href = "";
|
|
14
|
+
/**
|
|
15
|
+
* Big number (expects a pre-formatted text string)
|
|
16
|
+
* @type {string|number}
|
|
17
|
+
*/
|
|
18
|
+
export let value = "";
|
|
19
|
+
/**
|
|
20
|
+
* Mode for the data tile
|
|
21
|
+
* @type {"number"|"sparkline"|"bar"}
|
|
22
|
+
*/
|
|
23
|
+
export let mode = "number";
|
|
24
|
+
/**
|
|
25
|
+
* Text caption describing the number
|
|
26
|
+
* @type {string}
|
|
27
|
+
*/
|
|
28
|
+
export let caption = "";
|
|
29
|
+
/**
|
|
30
|
+
* An array of data (required for charts)
|
|
31
|
+
* @type {object[]|null}
|
|
32
|
+
*/
|
|
33
|
+
export let data = null;
|
|
34
|
+
/**
|
|
35
|
+
* Text describing the source of the data
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
38
|
+
export let source = "";
|
|
39
|
+
/**
|
|
40
|
+
* Optional: Set an additional CSS class for the component
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
43
|
+
export let cls = "";
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<Card {title} {href} mode="featured" {cls}>
|
|
47
|
+
{#if value}
|
|
48
|
+
<p class="headline-figures__figure ons-u-fs-3xl ons-u-fs-2xl@m">{value}</p>
|
|
49
|
+
{/if}
|
|
50
|
+
{#if caption}
|
|
51
|
+
<p class="headline-figures__supporting-text ons-u-fs-r">{@html caption}</p>
|
|
52
|
+
{/if}
|
|
53
|
+
{#if source}
|
|
54
|
+
<p class="ons-u-fs-s">{source}</p>
|
|
55
|
+
{/if}
|
|
56
|
+
</Card>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} DataTileProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} DataTileEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} DataTileSlots */
|
|
4
|
+
export default class DataTile extends SvelteComponentTyped<{
|
|
5
|
+
cls?: string | undefined;
|
|
6
|
+
caption?: string | undefined;
|
|
7
|
+
data?: object[] | null | undefined;
|
|
8
|
+
source?: string | undefined;
|
|
9
|
+
title?: string | undefined;
|
|
10
|
+
href?: string | undefined;
|
|
11
|
+
mode?: "number" | "sparkline" | "bar" | undefined;
|
|
12
|
+
value?: string | number | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
}, {}> {
|
|
16
|
+
}
|
|
17
|
+
export type DataTileProps = typeof __propDef.props;
|
|
18
|
+
export type DataTileEvents = typeof __propDef.events;
|
|
19
|
+
export type DataTileSlots = typeof __propDef.slots;
|
|
20
|
+
import { SvelteComponentTyped } from "svelte";
|
|
21
|
+
declare const __propDef: {
|
|
22
|
+
props: {
|
|
23
|
+
cls?: string | undefined;
|
|
24
|
+
caption?: string | undefined;
|
|
25
|
+
data?: object[] | null | undefined;
|
|
26
|
+
source?: string | undefined;
|
|
27
|
+
title?: string | undefined;
|
|
28
|
+
href?: string | undefined;
|
|
29
|
+
mode?: "number" | "sparkline" | "bar" | undefined;
|
|
30
|
+
value?: string | number | undefined;
|
|
31
|
+
};
|
|
32
|
+
events: {
|
|
33
|
+
[evt: string]: CustomEvent<any>;
|
|
34
|
+
};
|
|
35
|
+
slots: {};
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
A component for presenting key facts and figures in a tile grid.
|
|
2
|
+
|
|
3
|
+
Note: This component will be extended to include bar charts and sparklines.
|
|
4
|
+
|
|
5
|
+
<!-- prettier-ignore -->
|
|
6
|
+
```html
|
|
7
|
+
<script>
|
|
8
|
+
import { DataTile } from "@onsvisual/svelte-components";
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<DataTile
|
|
12
|
+
title="Consumer Price Index (CPI)",
|
|
13
|
+
value="up 2.5%",
|
|
14
|
+
caption="in 12 months to December 2024",
|
|
15
|
+
source="Source: ONS"
|
|
16
|
+
/>
|
|
17
|
+
```
|
|
@@ -39,12 +39,18 @@
|
|
|
39
39
|
Array.isArray(data) && data[0] ? Object.keys(data[0]).map((key) => ({ key, label: key })) : [];
|
|
40
40
|
let _data = [...data];
|
|
41
41
|
let sort = columns.map((c) => "none");
|
|
42
|
+
/**
|
|
43
|
+
* Optional: Set an additional CSS class for the component
|
|
44
|
+
* @type {string}
|
|
45
|
+
*/
|
|
46
|
+
export let cls = "";
|
|
42
47
|
|
|
43
48
|
$: sortable = columns.map((d) => d.sortable).includes(true);
|
|
44
49
|
$: formatters = columns.map((d) => formatter(d.dp));
|
|
45
50
|
</script>
|
|
46
51
|
|
|
47
52
|
<div
|
|
53
|
+
class={cls}
|
|
48
54
|
style:overflow={typeof height === "number" ? "auto" : null}
|
|
49
55
|
style:height={typeof height === "number" ? `${height}px` : null}
|
|
50
56
|
style:display={typeof height !== "number" ? "contents" : null}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} TableEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} TableSlots */
|
|
4
4
|
export default class Table extends SvelteComponentTyped<{
|
|
5
|
+
cls?: string | undefined;
|
|
5
6
|
height?: number | "auto" | undefined;
|
|
6
7
|
data?: object[] | undefined;
|
|
7
8
|
title?: string | undefined;
|
|
@@ -19,6 +20,7 @@ export type TableSlots = typeof __propDef.slots;
|
|
|
19
20
|
import { SvelteComponentTyped } from "svelte";
|
|
20
21
|
declare const __propDef: {
|
|
21
22
|
props: {
|
|
23
|
+
cls?: string | undefined;
|
|
22
24
|
height?: number | "auto" | undefined;
|
|
23
25
|
data?: object[] | undefined;
|
|
24
26
|
title?: string | undefined;
|
|
@@ -17,18 +17,23 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export let mode = "dark";
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Adds margin above section
|
|
21
21
|
* @type {boolean}
|
|
22
22
|
*/
|
|
23
23
|
export let marginTop = !!hr;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Adds margin below section
|
|
26
26
|
* @type {boolean}
|
|
27
27
|
*/
|
|
28
28
|
export let marginBottom = true;
|
|
29
|
+
/**
|
|
30
|
+
* Optional: Set an additional CSS class for the component
|
|
31
|
+
* @type {string}
|
|
32
|
+
*/
|
|
33
|
+
export let cls = "";
|
|
29
34
|
</script>
|
|
30
35
|
|
|
31
|
-
<Container {width} {marginTop} {marginBottom}>
|
|
36
|
+
<Container {width} {marginTop} {marginBottom} {cls}>
|
|
32
37
|
<hr
|
|
33
38
|
class="ons-u-mt-no"
|
|
34
39
|
class:ons-u-vh={!hr}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} DividerEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} DividerSlots */
|
|
4
4
|
export default class Divider extends SvelteComponentTyped<{
|
|
5
|
+
cls?: string | undefined;
|
|
5
6
|
width?: "narrow" | "medium" | "wide" | "wider" | "full" | undefined;
|
|
6
7
|
marginTop?: boolean | undefined;
|
|
7
8
|
marginBottom?: boolean | undefined;
|
|
@@ -17,6 +18,7 @@ export type DividerSlots = typeof __propDef.slots;
|
|
|
17
18
|
import { SvelteComponentTyped } from "svelte";
|
|
18
19
|
declare const __propDef: {
|
|
19
20
|
props: {
|
|
21
|
+
cls?: string | undefined;
|
|
20
22
|
width?: "narrow" | "medium" | "wide" | "wider" | "full" | undefined;
|
|
21
23
|
marginTop?: boolean | undefined;
|
|
22
24
|
marginBottom?: boolean | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export { default as Blockquote } from "./decorators/Blockquote/Blockquote.svelte
|
|
|
46
46
|
export { default as Divider } from "./decorators/Divider/Divider.svelte";
|
|
47
47
|
export { default as Em } from "./decorators/Em/Em.svelte";
|
|
48
48
|
export { default as Indent } from "./decorators/Indent/Indent.svelte";
|
|
49
|
+
export { default as DataTile } from "./datavis/DataTile/DataTile.svelte";
|
|
49
50
|
export { default as Table } from "./datavis/Table/Table.svelte";
|
|
50
51
|
export { default as AnalyticsBanner, analyticsEvent } from "./layout/AnalyticsBanner/AnalyticsBanner.svelte";
|
|
51
52
|
export { default as Details, default as Twisty } from "./layout/Details/Details.svelte";
|
package/dist/index.js
CHANGED
|
@@ -65,4 +65,5 @@ export { default as Em } from "./decorators/Em/Em.svelte";
|
|
|
65
65
|
export { default as Indent } from "./decorators/Indent/Indent.svelte";
|
|
66
66
|
|
|
67
67
|
// Data visualisation
|
|
68
|
+
export { default as DataTile } from "./datavis/DataTile/DataTile.svelte";
|
|
68
69
|
export { default as Table } from "./datavis/Table/Table.svelte";
|
|
@@ -54,6 +54,11 @@
|
|
|
54
54
|
* @type {string}
|
|
55
55
|
*/
|
|
56
56
|
export let download = "";
|
|
57
|
+
/**
|
|
58
|
+
* Optional: Set an additional CSS class for the component
|
|
59
|
+
* @type {string}
|
|
60
|
+
*/
|
|
61
|
+
export let cls = "";
|
|
57
62
|
</script>
|
|
58
63
|
|
|
59
64
|
{#if href}
|
|
@@ -61,7 +66,7 @@
|
|
|
61
66
|
href={!disabled ? href : null}
|
|
62
67
|
role="button"
|
|
63
68
|
{download}
|
|
64
|
-
class="ons-btn ons-btn--link ons-js-submit-btn"
|
|
69
|
+
class="ons-btn ons-btn--link ons-js-submit-btn {cls}"
|
|
65
70
|
class:ons-btn--small={small}
|
|
66
71
|
class:ons-btn--secondary={variant === "secondary"}
|
|
67
72
|
class:ons-btn--ghost={variant === "ghost"}
|
|
@@ -91,7 +96,7 @@
|
|
|
91
96
|
{:else}
|
|
92
97
|
<button
|
|
93
98
|
{type}
|
|
94
|
-
class="ons-btn"
|
|
99
|
+
class="ons-btn {cls}"
|
|
95
100
|
class:ons-btn--small={small}
|
|
96
101
|
class:ons-btn--secondary={variant === "secondary"}
|
|
97
102
|
class:ons-btn--ghost={variant === "ghost"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} ButtonEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} ButtonSlots */
|
|
4
4
|
export default class Button extends SvelteComponentTyped<{
|
|
5
|
+
cls?: string | undefined;
|
|
5
6
|
small?: boolean | undefined;
|
|
6
7
|
href?: string | undefined;
|
|
7
8
|
type?: "button" | "reset" | "sumbit" | undefined;
|
|
@@ -27,6 +28,7 @@ export type ButtonSlots = typeof __propDef.slots;
|
|
|
27
28
|
import { SvelteComponentTyped } from "svelte";
|
|
28
29
|
declare const __propDef: {
|
|
29
30
|
props: {
|
|
31
|
+
cls?: string | undefined;
|
|
30
32
|
small?: boolean | undefined;
|
|
31
33
|
href?: string | undefined;
|
|
32
34
|
type?: "button" | "reset" | "sumbit" | undefined;
|
|
@@ -9,50 +9,55 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export let id;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Label for input
|
|
13
13
|
* @type {string}
|
|
14
14
|
*/
|
|
15
|
-
export let
|
|
16
|
-
/**
|
|
17
|
-
* Value for input element (defaults to ID)
|
|
18
|
-
* @type {string|object}
|
|
19
|
-
*/
|
|
20
|
-
export let value = id;
|
|
15
|
+
export let label;
|
|
21
16
|
/**
|
|
22
|
-
*
|
|
17
|
+
* Optional: Extended description for element
|
|
23
18
|
* @type {string}
|
|
24
19
|
*/
|
|
25
|
-
export let
|
|
20
|
+
export let description = "";
|
|
26
21
|
/**
|
|
27
22
|
* Binding for checked state of input
|
|
28
23
|
* @type {boolean}
|
|
29
24
|
*/
|
|
30
25
|
export let checked = false;
|
|
31
26
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @type {
|
|
27
|
+
* Option to disable input
|
|
28
|
+
* @type {boolean}
|
|
34
29
|
*/
|
|
35
|
-
export let
|
|
30
|
+
export let disabled = false;
|
|
36
31
|
/**
|
|
37
|
-
* Optional:
|
|
32
|
+
* Optional: Define the item as an object in the form {id, label, description?}
|
|
33
|
+
* @type {object}
|
|
34
|
+
*/
|
|
35
|
+
export let item = { id, label, description, checked, disabled };
|
|
36
|
+
/**
|
|
37
|
+
* Optional: Name of checkbox group
|
|
38
38
|
* @type {string}
|
|
39
39
|
*/
|
|
40
|
-
export let
|
|
40
|
+
export let groupName = "";
|
|
41
|
+
/**
|
|
42
|
+
* Binding for checked state of input
|
|
43
|
+
* @type {object[]|null}
|
|
44
|
+
*/
|
|
45
|
+
export let group = null;
|
|
41
46
|
/**
|
|
42
47
|
* Set display mode of checkbox
|
|
43
48
|
* @type {"default"|"ghost"}
|
|
44
49
|
*/
|
|
45
50
|
export let variant = "default";
|
|
46
|
-
/**
|
|
47
|
-
* Option to disable input
|
|
48
|
-
* @type {boolean}
|
|
49
|
-
*/
|
|
50
|
-
export let disabled = false;
|
|
51
51
|
/**
|
|
52
52
|
* Compact mode (no border)
|
|
53
53
|
* @type {boolean}
|
|
54
54
|
*/
|
|
55
55
|
export let compact = false;
|
|
56
|
+
/**
|
|
57
|
+
* Optional: Set an additional CSS class for the component
|
|
58
|
+
* @type {string}
|
|
59
|
+
*/
|
|
60
|
+
export let cls = "";
|
|
56
61
|
|
|
57
62
|
const checkboxes = getContext("checkboxes");
|
|
58
63
|
|
|
@@ -64,15 +69,19 @@
|
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
function updateGroup() {
|
|
67
|
-
const
|
|
68
|
-
|
|
72
|
+
const groupIndex = {};
|
|
73
|
+
for (const g of group) groupIndex[g.id] = g;
|
|
74
|
+
const newGroupIds = $checkboxes.filter((c) => c.checked).map((c) => c?.id);
|
|
75
|
+
if (newGroupIds.length !== group.length)
|
|
76
|
+
group = newGroupIds.map((id) => groupIndex[id] || item);
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
function doChange(e) {
|
|
80
|
+
checked = item.checked;
|
|
72
81
|
if (Array.isArray(group) && Array.isArray($checkboxes)) {
|
|
73
82
|
updateGroup();
|
|
74
83
|
}
|
|
75
|
-
dispatch("change", {
|
|
84
|
+
dispatch("change", { item, e });
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
onMount(() => {
|
|
@@ -92,45 +101,45 @@
|
|
|
92
101
|
</script>
|
|
93
102
|
|
|
94
103
|
<span
|
|
95
|
-
class="ons-checkboxes__item"
|
|
104
|
+
class="ons-checkboxes__item {cls}"
|
|
96
105
|
class:ons-checkboxes__item--ghost={variant === "ghost"}
|
|
97
106
|
class:ons-checkboxes__item--no-border={compact}
|
|
98
107
|
>
|
|
99
108
|
<span class="ons-checkbox" class:ons-checkbox--no-border={compact}>
|
|
100
109
|
<input
|
|
101
110
|
type="checkbox"
|
|
102
|
-
{id}
|
|
103
|
-
{
|
|
104
|
-
{
|
|
105
|
-
bind:checked
|
|
111
|
+
id={item.id}
|
|
112
|
+
name={groupName}
|
|
113
|
+
value={item}
|
|
114
|
+
bind:checked={item.checked}
|
|
106
115
|
class="ons-checkbox__input ons-js-checkbox"
|
|
107
|
-
{disabled}
|
|
108
|
-
aria-disabled={disabled}
|
|
116
|
+
disabled={item.disabled}
|
|
117
|
+
aria-disabled={item.disabled}
|
|
109
118
|
on:change={doChange}
|
|
110
119
|
bind:this={el}
|
|
111
120
|
/>
|
|
112
121
|
<label
|
|
113
122
|
class="ons-checkbox__label"
|
|
114
|
-
class:ons-label--with-description={description}
|
|
115
|
-
for={id}
|
|
116
|
-
id="{id}-label"
|
|
117
|
-
aria-describedby={description ? `${id}-label-description-hint` : null}
|
|
123
|
+
class:ons-label--with-description={item.description}
|
|
124
|
+
for={item.id}
|
|
125
|
+
id="{item.id}-label"
|
|
126
|
+
aria-describedby={item.description ? `${item.id}-label-description-hint` : null}
|
|
118
127
|
>
|
|
119
|
-
{label}
|
|
120
|
-
{#if description}
|
|
128
|
+
{item.label}
|
|
129
|
+
{#if item.description}
|
|
121
130
|
<span class="ons-label__aria-hidden-description" aria-hidden="true"
|
|
122
131
|
><span class="ons-label__description ons-radio__label--with-description">
|
|
123
|
-
{description}
|
|
132
|
+
{item.description}
|
|
124
133
|
</span></span
|
|
125
134
|
>
|
|
126
135
|
{/if}
|
|
127
136
|
</label>
|
|
128
|
-
{#if description}
|
|
137
|
+
{#if item.description}
|
|
129
138
|
<span
|
|
130
139
|
class="ons-label__visually-hidden-description ons-u-vh"
|
|
131
|
-
id="{id}-label-description-hint"
|
|
140
|
+
id="{item.id}-label-description-hint"
|
|
132
141
|
>
|
|
133
|
-
{description}
|
|
142
|
+
{item.description}
|
|
134
143
|
</span>
|
|
135
144
|
{/if}
|
|
136
145
|
</span>
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
export default class Checkbox extends SvelteComponentTyped<{
|
|
5
5
|
id: string;
|
|
6
6
|
label: string;
|
|
7
|
-
|
|
7
|
+
cls?: string | undefined;
|
|
8
8
|
group?: object[] | null | undefined;
|
|
9
9
|
compact?: boolean | undefined;
|
|
10
|
-
value?: string | object | undefined;
|
|
11
10
|
variant?: "default" | "ghost" | undefined;
|
|
12
11
|
disabled?: boolean | undefined;
|
|
13
|
-
checked?: boolean | undefined;
|
|
14
12
|
description?: string | undefined;
|
|
13
|
+
checked?: boolean | undefined;
|
|
14
|
+
item?: object | undefined;
|
|
15
|
+
groupName?: string | undefined;
|
|
15
16
|
}, {
|
|
16
17
|
change: CustomEvent<any>;
|
|
17
18
|
} & {
|
|
@@ -26,14 +27,15 @@ declare const __propDef: {
|
|
|
26
27
|
props: {
|
|
27
28
|
id: string;
|
|
28
29
|
label: string;
|
|
29
|
-
|
|
30
|
+
cls?: string | undefined;
|
|
30
31
|
group?: object[] | null | undefined;
|
|
31
32
|
compact?: boolean | undefined;
|
|
32
|
-
value?: string | object | undefined;
|
|
33
33
|
variant?: "default" | "ghost" | undefined;
|
|
34
34
|
disabled?: boolean | undefined;
|
|
35
|
-
checked?: boolean | undefined;
|
|
36
35
|
description?: string | undefined;
|
|
36
|
+
checked?: boolean | undefined;
|
|
37
|
+
item?: object | undefined;
|
|
38
|
+
groupName?: string | undefined;
|
|
37
39
|
};
|
|
38
40
|
events: {
|
|
39
41
|
change: CustomEvent<any>;
|
|
@@ -21,22 +21,14 @@
|
|
|
21
21
|
];
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
|
-
{
|
|
25
|
-
<div style:padding="12px">
|
|
26
|
-
<Checkboxes {...args} />
|
|
27
|
-
</div>
|
|
28
|
-
{/snippet}
|
|
24
|
+
<Story name="Default" args={{ label: "Select items", items }} />
|
|
29
25
|
|
|
30
|
-
<Story name="
|
|
31
|
-
|
|
32
|
-
<Story name="Compact without label" args={{ items, compact: true }} {template} />
|
|
26
|
+
<Story name="Compact without label" args={{ items, compact: true }} />
|
|
33
27
|
|
|
34
28
|
<Story name="Individually defined checkboxes" asChild parameters={withStoryDocs(exampleDocs)}>
|
|
35
|
-
<
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</Checkboxes>
|
|
41
|
-
</div>
|
|
29
|
+
<Checkboxes label="Select items">
|
|
30
|
+
<Checkbox id="ice-cream" label="Ice cream" />
|
|
31
|
+
<Checkbox id="sprinkles" label="Sprinkles" description="Highly recommended!" />
|
|
32
|
+
<Checkbox id="disabled" label="Disabled option" disabled />
|
|
33
|
+
</Checkboxes>
|
|
42
34
|
</Story>
|
|
@@ -4,7 +4,17 @@
|
|
|
4
4
|
import Checkbox from "../Checkbox/Checkbox.svelte";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Title/legend for parent <fieldset>
|
|
8
|
+
* @type {string}
|
|
9
|
+
*/
|
|
10
|
+
export let title = "";
|
|
11
|
+
/**
|
|
12
|
+
* Visually hide the title/legend
|
|
13
|
+
* @type {boolean}
|
|
14
|
+
*/
|
|
15
|
+
export let hideTitle = false;
|
|
16
|
+
/**
|
|
17
|
+
* Descriptive "how to" label for inputs
|
|
8
18
|
* @type {string}
|
|
9
19
|
*/
|
|
10
20
|
export let label = "";
|
|
@@ -20,19 +30,33 @@
|
|
|
20
30
|
* @type {object[]}
|
|
21
31
|
*/
|
|
22
32
|
export let value = [];
|
|
33
|
+
/**
|
|
34
|
+
* Optional: Set an additional CSS class for the component
|
|
35
|
+
* @type {string}
|
|
36
|
+
*/
|
|
37
|
+
export let cls = "";
|
|
23
38
|
|
|
24
39
|
const checkboxes = writable([]);
|
|
25
40
|
setContext("checkboxes", checkboxes);
|
|
26
41
|
</script>
|
|
27
42
|
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
{#if Array.isArray(items)}
|
|
34
|
-
{#each items as item}
|
|
35
|
-
<Checkbox {...item} bind:group={value} {compact} on:change />
|
|
36
|
-
{/each}
|
|
43
|
+
<fieldset class="ons-fieldset {cls}">
|
|
44
|
+
{#if title}
|
|
45
|
+
<legend class="ons-fieldset__legend ons-u-mb-no">
|
|
46
|
+
<span class="ons-fieldset__legend-title ons-u-pb-no" class:ons-u-vh={hideTitle}>{title}</span>
|
|
47
|
+
</legend>
|
|
37
48
|
{/if}
|
|
38
|
-
|
|
49
|
+
<div class="ons-input-items">
|
|
50
|
+
{#if label}
|
|
51
|
+
<p class="ons-checkboxes__label">{label}</p>
|
|
52
|
+
{/if}
|
|
53
|
+
<div class="ons-checkboxes__items">
|
|
54
|
+
<slot />
|
|
55
|
+
{#if Array.isArray(items)}
|
|
56
|
+
{#each items as item}
|
|
57
|
+
<Checkbox {item} bind:group={value} {compact} on:change />
|
|
58
|
+
{/each}
|
|
59
|
+
{/if}
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</fieldset>
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} CheckboxesEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} CheckboxesSlots */
|
|
4
4
|
export default class Checkboxes extends SvelteComponentTyped<{
|
|
5
|
+
cls?: string | undefined;
|
|
5
6
|
label?: string | undefined;
|
|
7
|
+
title?: string | undefined;
|
|
6
8
|
compact?: boolean | undefined;
|
|
9
|
+
hideTitle?: boolean | undefined;
|
|
7
10
|
items?: object[] | null | undefined;
|
|
8
11
|
value?: object[] | undefined;
|
|
9
12
|
}, {
|
|
@@ -20,8 +23,11 @@ export type CheckboxesSlots = typeof __propDef.slots;
|
|
|
20
23
|
import { SvelteComponentTyped } from "svelte";
|
|
21
24
|
declare const __propDef: {
|
|
22
25
|
props: {
|
|
26
|
+
cls?: string | undefined;
|
|
23
27
|
label?: string | undefined;
|
|
28
|
+
title?: string | undefined;
|
|
24
29
|
compact?: boolean | undefined;
|
|
30
|
+
hideTitle?: boolean | undefined;
|
|
25
31
|
items?: object[] | null | undefined;
|
|
26
32
|
value?: object[] | undefined;
|
|
27
33
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
A component for defining a group of [checkbox](/docs/inputs-checkbox--docs) elements, whose checked values can be bound to Svelte variables, or grouped in an array.
|
|
2
2
|
|
|
3
|
-
Based on [this ONS Design System component](https://service-manual.ons.gov.uk/design-system/components/checkboxes).
|
|
3
|
+
Based on [this ONS Design System component](https://service-manual.ons.gov.uk/design-system/components/checkboxes). (Note: In some use cases, it may be preferable to use raw HTML `<input type="checkbox">` components and style these using CSS.)
|
|
4
4
|
|
|
5
5
|
<!-- prettier-ignore -->
|
|
6
6
|
```html
|
|
@@ -33,9 +33,14 @@
|
|
|
33
33
|
* @type {object[]}
|
|
34
34
|
*/
|
|
35
35
|
export let options = [];
|
|
36
|
+
/**
|
|
37
|
+
* Optional: Set an additional CSS class for the component
|
|
38
|
+
* @type {string}
|
|
39
|
+
*/
|
|
40
|
+
export let cls = "";
|
|
36
41
|
</script>
|
|
37
42
|
|
|
38
|
-
<div class="ons-field">
|
|
43
|
+
<div class="ons-field {cls}">
|
|
39
44
|
{#if label}
|
|
40
45
|
<label class="ons-label" for={id} class:ons-u-vh={hideLabel}>{label}</label>
|
|
41
46
|
{/if}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} DropdownEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} DropdownSlots */
|
|
4
4
|
export default class Dropdown extends SvelteComponentTyped<{
|
|
5
|
+
cls?: string | undefined;
|
|
5
6
|
id?: string | undefined;
|
|
6
7
|
label?: string | undefined;
|
|
7
8
|
value?: object | null | undefined;
|
|
@@ -20,6 +21,7 @@ export type DropdownSlots = typeof __propDef.slots;
|
|
|
20
21
|
import { SvelteComponentTyped } from "svelte";
|
|
21
22
|
declare const __propDef: {
|
|
22
23
|
props: {
|
|
24
|
+
cls?: string | undefined;
|
|
23
25
|
id?: string | undefined;
|
|
24
26
|
label?: string | undefined;
|
|
25
27
|
value?: object | null | undefined;
|