@onsvisual/svelte-components 1.0.0-next.3 → 1.0.0-next.5
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 +51 -0
- package/dist/datavis/DataTile/DataTile.svelte.d.ts +35 -0
- package/dist/datavis/DataTile/docs/component.md +17 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inputs/Checkbox/Checkbox.svelte +42 -38
- package/dist/inputs/Checkbox/Checkbox.svelte.d.ts +6 -6
- package/dist/inputs/Checkboxes/Checkboxes.stories.svelte +7 -15
- package/dist/inputs/Checkboxes/Checkboxes.svelte +30 -11
- package/dist/inputs/Checkboxes/Checkboxes.svelte.d.ts +4 -0
- package/dist/inputs/Checkboxes/docs/component.md +1 -1
- package/dist/inputs/Radios/Radio.svelte +31 -22
- package/dist/inputs/Radios/Radio.svelte.d.ts +8 -6
- package/dist/inputs/Radios/Radios.svelte +30 -19
- package/dist/inputs/Radios/Radios.svelte.d.ts +6 -2
- package/dist/inputs/Radios/docs/component.md +2 -2
- package/dist/intro.mdx +9 -2
- package/dist/layout/Breadcrumb/Breadcrumb.svelte +6 -1
- package/dist/layout/Breadcrumb/Breadcrumb.svelte.d.ts +2 -0
- package/dist/layout/Card/Card.stories.svelte +1 -1
- package/dist/layout/Card/Card.svelte +10 -1
- package/dist/layout/Card/Card.svelte.d.ts +2 -0
- 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,51 @@
|
|
|
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
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<Card {title} {href} mode="featured">
|
|
42
|
+
{#if value}
|
|
43
|
+
<p class="headline-figures__figure ons-u-fs-3xl ons-u-fs-2xl@m">{value}</p>
|
|
44
|
+
{/if}
|
|
45
|
+
{#if caption}
|
|
46
|
+
<p class="headline-figures__supporting-text ons-u-fs-r">{@html caption}</p>
|
|
47
|
+
{/if}
|
|
48
|
+
{#if source}
|
|
49
|
+
<p class="ons-u-fs-s">{source}</p>
|
|
50
|
+
{/if}
|
|
51
|
+
</Card>
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
caption?: string | undefined;
|
|
6
|
+
data?: object[] | null | undefined;
|
|
7
|
+
source?: string | undefined;
|
|
8
|
+
title?: string | undefined;
|
|
9
|
+
href?: string | undefined;
|
|
10
|
+
mode?: "number" | "sparkline" | "bar" | undefined;
|
|
11
|
+
value?: string | number | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
[evt: string]: CustomEvent<any>;
|
|
14
|
+
}, {}> {
|
|
15
|
+
}
|
|
16
|
+
export type DataTileProps = typeof __propDef.props;
|
|
17
|
+
export type DataTileEvents = typeof __propDef.events;
|
|
18
|
+
export type DataTileSlots = typeof __propDef.slots;
|
|
19
|
+
import { SvelteComponentTyped } from "svelte";
|
|
20
|
+
declare const __propDef: {
|
|
21
|
+
props: {
|
|
22
|
+
caption?: string | undefined;
|
|
23
|
+
data?: object[] | null | undefined;
|
|
24
|
+
source?: string | undefined;
|
|
25
|
+
title?: string | undefined;
|
|
26
|
+
href?: string | undefined;
|
|
27
|
+
mode?: "number" | "sparkline" | "bar" | undefined;
|
|
28
|
+
value?: string | number | undefined;
|
|
29
|
+
};
|
|
30
|
+
events: {
|
|
31
|
+
[evt: string]: CustomEvent<any>;
|
|
32
|
+
};
|
|
33
|
+
slots: {};
|
|
34
|
+
};
|
|
35
|
+
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
|
+
```
|
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";
|
|
@@ -9,45 +9,45 @@
|
|
|
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}
|
|
@@ -64,15 +64,19 @@
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
function updateGroup() {
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const groupIndex = {};
|
|
68
|
+
for (const g of group) groupIndex[g.id] = g;
|
|
69
|
+
const newGroupIds = $checkboxes.filter((c) => c.checked).map((c) => c?.id);
|
|
70
|
+
if (newGroupIds.length !== group.length)
|
|
71
|
+
group = newGroupIds.map((id) => groupIndex[id] || item);
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
function doChange(e) {
|
|
75
|
+
checked = item.checked;
|
|
72
76
|
if (Array.isArray(group) && Array.isArray($checkboxes)) {
|
|
73
77
|
updateGroup();
|
|
74
78
|
}
|
|
75
|
-
dispatch("change", {
|
|
79
|
+
dispatch("change", { item, e });
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
onMount(() => {
|
|
@@ -99,38 +103,38 @@
|
|
|
99
103
|
<span class="ons-checkbox" class:ons-checkbox--no-border={compact}>
|
|
100
104
|
<input
|
|
101
105
|
type="checkbox"
|
|
102
|
-
{id}
|
|
103
|
-
{
|
|
104
|
-
{
|
|
105
|
-
bind:checked
|
|
106
|
+
id={item.id}
|
|
107
|
+
name={groupName}
|
|
108
|
+
value={item}
|
|
109
|
+
bind:checked={item.checked}
|
|
106
110
|
class="ons-checkbox__input ons-js-checkbox"
|
|
107
|
-
{disabled}
|
|
108
|
-
aria-disabled={disabled}
|
|
111
|
+
disabled={item.disabled}
|
|
112
|
+
aria-disabled={item.disabled}
|
|
109
113
|
on:change={doChange}
|
|
110
114
|
bind:this={el}
|
|
111
115
|
/>
|
|
112
116
|
<label
|
|
113
117
|
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}
|
|
118
|
+
class:ons-label--with-description={item.description}
|
|
119
|
+
for={item.id}
|
|
120
|
+
id="{item.id}-label"
|
|
121
|
+
aria-describedby={item.description ? `${item.id}-label-description-hint` : null}
|
|
118
122
|
>
|
|
119
|
-
{label}
|
|
120
|
-
{#if description}
|
|
123
|
+
{item.label}
|
|
124
|
+
{#if item.description}
|
|
121
125
|
<span class="ons-label__aria-hidden-description" aria-hidden="true"
|
|
122
126
|
><span class="ons-label__description ons-radio__label--with-description">
|
|
123
|
-
{description}
|
|
127
|
+
{item.description}
|
|
124
128
|
</span></span
|
|
125
129
|
>
|
|
126
130
|
{/if}
|
|
127
131
|
</label>
|
|
128
|
-
{#if description}
|
|
132
|
+
{#if item.description}
|
|
129
133
|
<span
|
|
130
134
|
class="ons-label__visually-hidden-description ons-u-vh"
|
|
131
|
-
id="{id}-label-description-hint"
|
|
135
|
+
id="{item.id}-label-description-hint"
|
|
132
136
|
>
|
|
133
|
-
{description}
|
|
137
|
+
{item.description}
|
|
134
138
|
</span>
|
|
135
139
|
{/if}
|
|
136
140
|
</span>
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
export default class Checkbox extends SvelteComponentTyped<{
|
|
5
5
|
id: string;
|
|
6
6
|
label: string;
|
|
7
|
-
name?: string | undefined;
|
|
8
7
|
group?: object[] | null | undefined;
|
|
9
8
|
compact?: boolean | undefined;
|
|
10
|
-
value?: string | object | undefined;
|
|
11
9
|
variant?: "default" | "ghost" | undefined;
|
|
12
10
|
disabled?: boolean | undefined;
|
|
13
|
-
checked?: boolean | undefined;
|
|
14
11
|
description?: string | undefined;
|
|
12
|
+
checked?: boolean | undefined;
|
|
13
|
+
item?: object | undefined;
|
|
14
|
+
groupName?: string | undefined;
|
|
15
15
|
}, {
|
|
16
16
|
change: CustomEvent<any>;
|
|
17
17
|
} & {
|
|
@@ -26,14 +26,14 @@ declare const __propDef: {
|
|
|
26
26
|
props: {
|
|
27
27
|
id: string;
|
|
28
28
|
label: string;
|
|
29
|
-
name?: string | undefined;
|
|
30
29
|
group?: object[] | null | undefined;
|
|
31
30
|
compact?: boolean | undefined;
|
|
32
|
-
value?: string | object | undefined;
|
|
33
31
|
variant?: "default" | "ghost" | undefined;
|
|
34
32
|
disabled?: boolean | undefined;
|
|
35
|
-
checked?: boolean | undefined;
|
|
36
33
|
description?: string | undefined;
|
|
34
|
+
checked?: boolean | undefined;
|
|
35
|
+
item?: object | undefined;
|
|
36
|
+
groupName?: string | undefined;
|
|
37
37
|
};
|
|
38
38
|
events: {
|
|
39
39
|
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 = "";
|
|
@@ -25,14 +35,23 @@
|
|
|
25
35
|
setContext("checkboxes", checkboxes);
|
|
26
36
|
</script>
|
|
27
37
|
|
|
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}
|
|
38
|
+
<fieldset class="ons-fieldset">
|
|
39
|
+
{#if title}
|
|
40
|
+
<legend class="ons-fieldset__legend ons-u-mb-no">
|
|
41
|
+
<span class="ons-fieldset__legend-title ons-u-pb-no" class:ons-u-vh={hideTitle}>{title}</span>
|
|
42
|
+
</legend>
|
|
37
43
|
{/if}
|
|
38
|
-
|
|
44
|
+
<div class="ons-input-items">
|
|
45
|
+
{#if label}
|
|
46
|
+
<p class="ons-checkboxes__label">{label}</p>
|
|
47
|
+
{/if}
|
|
48
|
+
<div class="ons-checkboxes__items">
|
|
49
|
+
<slot />
|
|
50
|
+
{#if Array.isArray(items)}
|
|
51
|
+
{#each items as item}
|
|
52
|
+
<Checkbox {item} bind:group={value} {compact} on:change />
|
|
53
|
+
{/each}
|
|
54
|
+
{/if}
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</fieldset>
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
/** @typedef {typeof __propDef.slots} CheckboxesSlots */
|
|
4
4
|
export default class Checkboxes extends SvelteComponentTyped<{
|
|
5
5
|
label?: string | undefined;
|
|
6
|
+
title?: string | undefined;
|
|
6
7
|
compact?: boolean | undefined;
|
|
8
|
+
hideTitle?: boolean | undefined;
|
|
7
9
|
items?: object[] | null | undefined;
|
|
8
10
|
value?: object[] | undefined;
|
|
9
11
|
}, {
|
|
@@ -21,7 +23,9 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
21
23
|
declare const __propDef: {
|
|
22
24
|
props: {
|
|
23
25
|
label?: string | undefined;
|
|
26
|
+
title?: string | undefined;
|
|
24
27
|
compact?: boolean | undefined;
|
|
28
|
+
hideTitle?: boolean | undefined;
|
|
25
29
|
items?: object[] | null | undefined;
|
|
26
30
|
value?: object[] | undefined;
|
|
27
31
|
};
|
|
@@ -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
|
|
@@ -7,27 +7,32 @@
|
|
|
7
7
|
* Unique ID input
|
|
8
8
|
* @type {string}
|
|
9
9
|
*/
|
|
10
|
-
export let id;
|
|
10
|
+
export let id = "";
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Label for input
|
|
13
13
|
* @type {string}
|
|
14
14
|
*/
|
|
15
|
-
export let
|
|
15
|
+
export let label = "";
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Optional: Extended description for element
|
|
18
18
|
* @type {string}
|
|
19
19
|
*/
|
|
20
|
-
export let
|
|
20
|
+
export let description = "";
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @type {
|
|
22
|
+
* Optional: Define the item as an object in the form {id, label, description?}
|
|
23
|
+
* @type {object}
|
|
24
24
|
*/
|
|
25
|
-
export let
|
|
25
|
+
export let item = { id, label, description };
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* ID for radio group (required)
|
|
28
28
|
* @type {string}
|
|
29
29
|
*/
|
|
30
|
-
export let
|
|
30
|
+
export let groupId;
|
|
31
|
+
/**
|
|
32
|
+
* Binding selected option
|
|
33
|
+
* @type {object|null}
|
|
34
|
+
*/
|
|
35
|
+
export let value = null;
|
|
31
36
|
/**
|
|
32
37
|
* Compact mode (no border)
|
|
33
38
|
* @type {boolean}
|
|
@@ -39,35 +44,39 @@
|
|
|
39
44
|
<span class="ons-radio" class:ons-radio--no-border={compact}>
|
|
40
45
|
<input
|
|
41
46
|
type="radio"
|
|
42
|
-
{id}
|
|
43
|
-
|
|
44
|
-
value={id}
|
|
47
|
+
id={item.id}
|
|
48
|
+
value={item}
|
|
45
49
|
name={groupId}
|
|
46
50
|
class="ons-radio__input ons-js-radio"
|
|
47
|
-
on:change={(e) =>
|
|
51
|
+
on:change={(e) => {
|
|
52
|
+
if (e?.target?.checked) {
|
|
53
|
+
value = item;
|
|
54
|
+
dispatch("change", { value, e });
|
|
55
|
+
}
|
|
56
|
+
}}
|
|
48
57
|
/>
|
|
49
58
|
<label
|
|
50
59
|
class="ons-radio__label"
|
|
51
60
|
class:ons-label--with-description={description}
|
|
52
|
-
for={id}
|
|
53
|
-
id="{id}-label"
|
|
54
|
-
aria-describedby={description ? `${id}-label-description-hint` : null}
|
|
61
|
+
for={item.id}
|
|
62
|
+
id="{item.id}-label"
|
|
63
|
+
aria-describedby={item.description ? `${item.id}-label-description-hint` : null}
|
|
55
64
|
>
|
|
56
|
-
{label}
|
|
57
|
-
{#if description}
|
|
65
|
+
{item.label}
|
|
66
|
+
{#if item.description}
|
|
58
67
|
<span class="ons-label__aria-hidden-description" aria-hidden="true"
|
|
59
68
|
><span class="ons-label__description ons-radio__label--with-description">
|
|
60
|
-
{description}
|
|
69
|
+
{item.description}
|
|
61
70
|
</span></span
|
|
62
71
|
>
|
|
63
72
|
{/if}
|
|
64
73
|
</label>
|
|
65
|
-
{#if description}
|
|
74
|
+
{#if item.description}
|
|
66
75
|
<span
|
|
67
76
|
class="ons-label__visually-hidden-description ons-u-vh"
|
|
68
77
|
id="{id}-label-description-hint"
|
|
69
78
|
>
|
|
70
|
-
{description}
|
|
79
|
+
{item.description}
|
|
71
80
|
</span>
|
|
72
81
|
{/if}
|
|
73
82
|
</span>
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} RadioEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} RadioSlots */
|
|
4
4
|
export default class Radio extends SvelteComponentTyped<{
|
|
5
|
-
id: string;
|
|
6
|
-
label: string;
|
|
7
5
|
groupId: string;
|
|
6
|
+
id?: string | undefined;
|
|
7
|
+
label?: string | undefined;
|
|
8
8
|
compact?: boolean | undefined;
|
|
9
|
-
value?:
|
|
9
|
+
value?: object | null | undefined;
|
|
10
10
|
description?: string | undefined;
|
|
11
|
+
item?: object | undefined;
|
|
11
12
|
}, {
|
|
12
13
|
change: CustomEvent<any>;
|
|
13
14
|
} & {
|
|
@@ -20,12 +21,13 @@ export type RadioSlots = typeof __propDef.slots;
|
|
|
20
21
|
import { SvelteComponentTyped } from "svelte";
|
|
21
22
|
declare const __propDef: {
|
|
22
23
|
props: {
|
|
23
|
-
id: string;
|
|
24
|
-
label: string;
|
|
25
24
|
groupId: string;
|
|
25
|
+
id?: string | undefined;
|
|
26
|
+
label?: string | undefined;
|
|
26
27
|
compact?: boolean | undefined;
|
|
27
|
-
value?:
|
|
28
|
+
value?: object | null | undefined;
|
|
28
29
|
description?: string | undefined;
|
|
30
|
+
item?: object | undefined;
|
|
29
31
|
};
|
|
30
32
|
events: {
|
|
31
33
|
change: CustomEvent<any>;
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import Radio from "./Radio.svelte";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Title/legend for parent <fieldset>
|
|
6
|
+
* @type {string}
|
|
7
|
+
*/
|
|
8
|
+
export let title = "";
|
|
9
|
+
/**
|
|
10
|
+
* Visually hide the title/legend
|
|
11
|
+
* @type {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export let hideTitle = false;
|
|
4
14
|
/**
|
|
5
15
|
* Unique ID for radio group (required)
|
|
6
16
|
* @type {string}
|
|
7
17
|
*/
|
|
8
18
|
export let id = "name";
|
|
9
19
|
/**
|
|
10
|
-
*
|
|
20
|
+
* Descriptive "how to" label for inputs
|
|
11
21
|
* @type {string}
|
|
12
22
|
*/
|
|
13
23
|
export let label = "";
|
|
14
24
|
/**
|
|
15
25
|
* Binding for ID of selected option
|
|
16
|
-
* @type {
|
|
26
|
+
* @type {object|null}
|
|
17
27
|
*/
|
|
18
28
|
export let value = null;
|
|
19
29
|
/** Optional: Define the radios as an array of {id, label, description?}
|
|
@@ -27,20 +37,21 @@
|
|
|
27
37
|
export let compact = false;
|
|
28
38
|
</script>
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</div>
|
|
40
|
+
<fieldset class="ons-fieldset">
|
|
41
|
+
{#if title}
|
|
42
|
+
<legend class="ons-fieldset__legend ons-u-mb-no">
|
|
43
|
+
<span class="ons-fieldset__legend-title ons-u-pb-no" class:ons-u-vh={hideTitle}>{title}</span>
|
|
44
|
+
</legend>
|
|
45
|
+
{/if}
|
|
46
|
+
<div class="ons-input-items">
|
|
47
|
+
{#if label}
|
|
48
|
+
<p class="ons-radios__label">{label}</p>
|
|
49
|
+
{/if}
|
|
50
|
+
<div class="ons-radios__items">
|
|
51
|
+
<slot />
|
|
52
|
+
{#each items as item}
|
|
53
|
+
<Radio {item} groupId={id} {compact} bind:value on:change />
|
|
54
|
+
{/each}
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</fieldset>
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
export default class Radios extends SvelteComponentTyped<{
|
|
5
5
|
id?: string | undefined;
|
|
6
6
|
label?: string | undefined;
|
|
7
|
+
title?: string | undefined;
|
|
7
8
|
compact?: boolean | undefined;
|
|
9
|
+
hideTitle?: boolean | undefined;
|
|
8
10
|
items?: object[] | undefined;
|
|
9
|
-
value?:
|
|
11
|
+
value?: object | null | undefined;
|
|
10
12
|
}, {
|
|
11
13
|
change: CustomEvent<any>;
|
|
12
14
|
} & {
|
|
@@ -23,9 +25,11 @@ declare const __propDef: {
|
|
|
23
25
|
props: {
|
|
24
26
|
id?: string | undefined;
|
|
25
27
|
label?: string | undefined;
|
|
28
|
+
title?: string | undefined;
|
|
26
29
|
compact?: boolean | undefined;
|
|
30
|
+
hideTitle?: boolean | undefined;
|
|
27
31
|
items?: object[] | undefined;
|
|
28
|
-
value?:
|
|
32
|
+
value?: object | null | undefined;
|
|
29
33
|
};
|
|
30
34
|
events: {
|
|
31
35
|
change: CustomEvent<any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
A component for defining a group of radio inputs, where the selected item id can be bound to a Svelte variable.
|
|
2
2
|
|
|
3
|
-
Based on [this ONS Design System component](https://service-manual.ons.gov.uk/design-system/components/radios).
|
|
3
|
+
Based on [this ONS Design System component](https://service-manual.ons.gov.uk/design-system/components/radios). (Note: In some use cases, it may be preferable to use raw HTML `<input type="radio">` components and style these using CSS.)
|
|
4
4
|
|
|
5
5
|
<!-- prettier-ignore -->
|
|
6
6
|
```html
|
|
@@ -17,7 +17,7 @@ Based on [this ONS Design System component](https://service-manual.ons.gov.uk/de
|
|
|
17
17
|
{ id: "mobile", label: "Caravan or other mobile or temporary structure" },
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
-
let selected; // A binding for the selected item
|
|
20
|
+
let selected; // A binding for the selected item
|
|
21
21
|
</script>
|
|
22
22
|
|
|
23
23
|
<Radios {items} bind:value={selected} label="Select one">
|
package/dist/intro.mdx
CHANGED
|
@@ -47,14 +47,21 @@ npm install @onsvisual/svelte-components --save-dev
|
|
|
47
47
|
|
|
48
48
|
## Using the components
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
When using the components, you need to import both the desired component and the global CSS styles. In a SvelteKit project it is best to import the CSS in a top-level **+layout.svelte** file in your **src/routes** folder, which will apply it to all pages/components in the project.
|
|
51
51
|
|
|
52
52
|
{/* prettier-ignore */}
|
|
53
53
|
```html
|
|
54
|
+
<!-- +layout.svelte -->
|
|
54
55
|
<script>
|
|
55
56
|
import "@onsvisual/svelte-components/css/main.css";
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<slot/>
|
|
60
|
+
|
|
61
|
+
<!-- +page.svelte / Component.svelte -->
|
|
62
|
+
<script>
|
|
56
63
|
import { Section } from "@onsvisual/svelte-components";
|
|
57
64
|
</script>
|
|
58
65
|
|
|
59
|
-
<Section title="Hello world!">
|
|
66
|
+
<Section title="Hello world!">I am using an ONS Svelte component.</Section>
|
|
60
67
|
```
|
|
@@ -16,9 +16,14 @@
|
|
|
16
16
|
* @type {"narrow"|"medium"|"wide"|"wider"|"full"}
|
|
17
17
|
*/
|
|
18
18
|
export let width = "wide";
|
|
19
|
+
/**
|
|
20
|
+
* Overrides the base theme background (accepts any valid CSS background value)
|
|
21
|
+
* @type {string|null}
|
|
22
|
+
*/
|
|
23
|
+
export let background = null;
|
|
19
24
|
</script>
|
|
20
25
|
|
|
21
|
-
<Container {width}>
|
|
26
|
+
<Container {width} {background}>
|
|
22
27
|
<nav class="ons-breadcrumbs" aria-label="Breadcrumbs">
|
|
23
28
|
<ol class="ons-breadcrumbs__items ons-u-fs-s">
|
|
24
29
|
{#each backHref ? [{ label: "Back", href: backHref }] : links as link}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/** @typedef {typeof __propDef.slots} BreadcrumbSlots */
|
|
4
4
|
export default class Breadcrumb extends SvelteComponentTyped<{
|
|
5
5
|
width?: "narrow" | "medium" | "wide" | "wider" | "full" | undefined;
|
|
6
|
+
background?: string | null | undefined;
|
|
6
7
|
links?: object[] | undefined;
|
|
7
8
|
backHref?: string | undefined;
|
|
8
9
|
}, {
|
|
@@ -16,6 +17,7 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
16
17
|
declare const __propDef: {
|
|
17
18
|
props: {
|
|
18
19
|
width?: "narrow" | "medium" | "wide" | "wider" | "full" | undefined;
|
|
20
|
+
background?: string | null | undefined;
|
|
19
21
|
links?: object[] | undefined;
|
|
20
22
|
backHref?: string | undefined;
|
|
21
23
|
};
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
<Story name="Cards with links" args={{ href: "#0" }} {template} />
|
|
29
29
|
|
|
30
|
-
<Story name="Featured cards" args={{ mode: "featured" }} {template} />
|
|
30
|
+
<Story name="Featured cards with baseline" args={{ mode: "featured", baseline: true }} {template} />
|
|
31
31
|
|
|
32
32
|
<Story
|
|
33
33
|
name="Featured cards with image"
|
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
* @type {"default"|"featured"}
|
|
32
32
|
*/
|
|
33
33
|
export let mode = "default";
|
|
34
|
+
/**
|
|
35
|
+
* Include a border at the bottom of the card
|
|
36
|
+
* @type {boolean}
|
|
37
|
+
*/
|
|
38
|
+
export let baseline = false;
|
|
34
39
|
/**
|
|
35
40
|
* Optional: URL for title/image link
|
|
36
41
|
* @type {string}
|
|
@@ -58,9 +63,10 @@
|
|
|
58
63
|
class="ons-card ons-u-mb-no {cls}"
|
|
59
64
|
class:ons-card--feature={mode === "featured"}
|
|
60
65
|
class:ons-u-p-l={mode === "featured"}
|
|
66
|
+
class:ons-card--baseline={baseline}
|
|
61
67
|
>
|
|
62
68
|
{#if href}
|
|
63
|
-
<a href
|
|
69
|
+
<a {href} class="ons-card__link">
|
|
64
70
|
<slot name="image">
|
|
65
71
|
{#if image}
|
|
66
72
|
<img
|
|
@@ -117,4 +123,7 @@
|
|
|
117
123
|
.ons-card > :global(p:last-of-type) {
|
|
118
124
|
margin-bottom: 0;
|
|
119
125
|
}
|
|
126
|
+
.ons-card--baseline {
|
|
127
|
+
border-bottom: 2px solid var(--ons-color-borders-light);
|
|
128
|
+
}
|
|
120
129
|
</style>
|
|
@@ -11,6 +11,7 @@ export default class Card extends SvelteComponentTyped<{
|
|
|
11
11
|
colspan?: number | undefined;
|
|
12
12
|
hideTitle?: boolean | undefined;
|
|
13
13
|
mode?: "default" | "featured" | undefined;
|
|
14
|
+
baseline?: boolean | undefined;
|
|
14
15
|
imageAlt?: string | undefined;
|
|
15
16
|
}, {
|
|
16
17
|
[evt: string]: CustomEvent<any>;
|
|
@@ -35,6 +36,7 @@ declare const __propDef: {
|
|
|
35
36
|
colspan?: number | undefined;
|
|
36
37
|
hideTitle?: boolean | undefined;
|
|
37
38
|
mode?: "default" | "featured" | undefined;
|
|
39
|
+
baseline?: boolean | undefined;
|
|
38
40
|
imageAlt?: string | undefined;
|
|
39
41
|
};
|
|
40
42
|
events: {
|