@onsvisual/svelte-components 0.0.4 → 0.0.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.
Files changed (29) hide show
  1. package/dist/@types/datavis/Table/Table.svelte.d.ts +33 -0
  2. package/dist/@types/index.d.ts +17 -2
  3. package/dist/@types/inputs/Button/Button.svelte.d.ts +1 -1
  4. package/dist/@types/inputs/Dropdown/Dropdown.svelte.d.ts +2 -2
  5. package/dist/@types/inputs/Input/Input.svelte.d.ts +6 -6
  6. package/dist/@types/inputs/Select/Select.svelte.d.ts +4 -4
  7. package/dist/@types/inputs/Textarea/Textarea.svelte.d.ts +2 -2
  8. package/dist/@types/layout/Accordion/AccordionItem.svelte.d.ts +2 -2
  9. package/dist/@types/layout/Hero/Hero.svelte.d.ts +2 -2
  10. package/dist/@types/layout/List/List.svelte.d.ts +27 -0
  11. package/dist/@types/layout/NavSections/NavSection.svelte.d.ts +31 -0
  12. package/dist/@types/layout/NavSections/NavSections.svelte.d.ts +43 -0
  13. package/dist/@types/layout/NavSections/SectionBacklink.svelte.d.ts +23 -0
  14. package/dist/@types/layout/Scroller/ScrollerSection.svelte.d.ts +2 -2
  15. package/dist/@types/layout/Section/Section.svelte.d.ts +2 -2
  16. package/dist/@types/layout/TitleBlock/TitleBlock.svelte.d.ts +24 -4
  17. package/dist/css/main.css +2 -2
  18. package/dist/datavis/Table/Table.svelte +129 -0
  19. package/dist/index.js +21 -2
  20. package/dist/layout/List/List.svelte +32 -0
  21. package/dist/layout/NavSections/NavSection.svelte +51 -0
  22. package/dist/layout/NavSections/NavSections.svelte +92 -0
  23. package/dist/layout/NavSections/SectionBacklink.svelte +31 -0
  24. package/dist/layout/TitleBlock/TitleBlock.svelte +97 -0
  25. package/dist/wrappers/Embed/Embed.svelte +4 -2
  26. package/dist/wrappers/Theme/Theme.svelte +1 -1
  27. package/package.json +7 -2
  28. /package/dist/@types/{layout → decorators}/Divider/Divider.svelte.d.ts +0 -0
  29. /package/dist/{layout → decorators}/Divider/Divider.svelte +0 -0
@@ -0,0 +1,129 @@
1
+ <script>
2
+ import { commas, ascending, descending } from "$lib/js/utils.js";
3
+
4
+ /**
5
+ * An optional title for the table
6
+ * @type {string}
7
+ */
8
+ export let title = "";
9
+ /**
10
+ * Make the chart smaller/more compact
11
+ * @type {boolean}
12
+ */
13
+ export let compact = false;
14
+ /**
15
+ * Make the chart responsive (changes layout on narrow screens)
16
+ * @type {boolean}
17
+ */
18
+ export let responsive = false;
19
+ /**
20
+ * Highlight rows on hover
21
+ * @type {boolean}
22
+ */
23
+ export let rowHover = false;
24
+ /**
25
+ * Rows of data
26
+ * @type {array}
27
+ */
28
+ export let data = [];
29
+ /**
30
+ * Optional metadata for formatting columns. Array of {key, label, sortable?, numeric?} objects
31
+ * @type {array}
32
+ */
33
+ export let columns =
34
+ Array.isArray(data) && data[0] ? Object.keys(data[0]).map((key) => ({ key, label: key })) : [];
35
+ let _data = [...data];
36
+ let sort = columns.map((c) => "none");
37
+
38
+ const format = (val, numeric) => (numeric ? commas(val) : val);
39
+ $: sortable = columns.map((d) => d.sortable).includes(true);
40
+ </script>
41
+
42
+ <table
43
+ class="ons-table"
44
+ class:ons-table--sortable="{sortable}"
45
+ class:ons-table--compact="{compact}"
46
+ class:ons-table--responsive="{responsive}"
47
+ class:ons-table--row-hover="{rowHover}"
48
+ data-aria-sort="{sortable ? 'Sort by' : null}"
49
+ data-aria-asc="{sortable ? 'ascending' : null}"
50
+ data-aria-desc="{sortable ? 'descending' : null}"
51
+ >
52
+ {#if title}<caption class="ons-table__caption">{title}</caption>{/if}
53
+ <thead class="ons-table__head">
54
+ <tr class="ons-table__row">
55
+ {#each columns as col, i}
56
+ {#if col.sortable}
57
+ <th
58
+ scope="col"
59
+ class="ons-table__header"
60
+ class:ons-table__header--numeric="{col.numeric}"
61
+ aria-sort="{sort[i]}"
62
+ >
63
+ <button
64
+ aria-label="Sort by {col.label}"
65
+ type="button"
66
+ data-index="{i}"
67
+ class="ons-table__sort-button"
68
+ on:click="{() => {
69
+ sort = sort.map((c, j) =>
70
+ j === i && c === 'ascending' ? 'descending' : j === i ? 'ascending' : 'none'
71
+ );
72
+ _data = _data.sort((a, b) =>
73
+ sort[i] === 'ascending'
74
+ ? ascending(a[col.key], b[col.key])
75
+ : descending(a[col.key], b[col.key])
76
+ );
77
+ }}"
78
+ >
79
+ {col.label}<svg
80
+ class="ons-svg-icon"
81
+ viewBox="0 0 12 19"
82
+ xmlns="http://www.w3.org/2000/svg"
83
+ focusable="false"
84
+ fill="currentColor"
85
+ >
86
+ <path
87
+ class="ons-topTriangle"
88
+ d="M6 0l6 7.2H0L6 0zm0 18.6l6-7.2H0l6 7.2zm0 3.6l6 7.2H0l6-7.2z"></path>
89
+ <path class="ons-bottomTriangle" d="M6 18.6l6-7.2H0l6 7.2zm0 3.6l6 7.2H0l6-7.2z"
90
+ ></path>
91
+ </svg>
92
+ </button>
93
+ </th>
94
+ {:else}
95
+ <th
96
+ scope="col"
97
+ class="ons-table__header"
98
+ class:ons-table__header--numeric="{col.numeric}"
99
+ >
100
+ <span class="ons-table__header-text">{col.label}</span>
101
+ </th>
102
+ {/if}
103
+ {/each}
104
+ </tr>
105
+ </thead>
106
+ <tbody class="ons-table__body">
107
+ {#each _data as row}
108
+ <tr class="ons-table__row">
109
+ {#each columns as col}
110
+ <td
111
+ class="ons-table__cell"
112
+ class:ons-table__cell--numeric="{col.numeric}"
113
+ data-th="{col.label}">{format(row[col.key], col.numeric)}</td
114
+ >
115
+ {/each}
116
+ </tr>
117
+ {/each}
118
+ </tbody>
119
+ </table>
120
+
121
+ <style>
122
+ .ons-table__sort-button {
123
+ color: var(--link, --ons-color-text-link) !important;
124
+ }
125
+ .ons-table__sort-button:hover {
126
+ color: var(--link-hover, --ons-color-text-link-hover) !important;
127
+ -webkit-text-decoration: underline solid var(--link-hover, --ons-color-text-link-hover) 2px !important;
128
+ text-decoration: underline solid var(--link-hover, --ons-color-text-link-hover) 2px !important;
129
+ }</style>
package/dist/index.js CHANGED
@@ -1,17 +1,36 @@
1
1
  // Wrappers
2
- export { default as Theme } from "./wrappers/Theme/Theme.svelte";
3
2
  export { default as Container } from "./wrappers/Container/Container.svelte";
3
+ export { default as Embed } from "./wrappers/Embed/Embed.svelte";
4
+ export { default as Main } from "./wrappers/Main/Main.svelte";
5
+ export { default as Theme } from "./wrappers/Theme/Theme.svelte";
4
6
 
5
7
  // Layout
6
8
  export { default as Accordion } from "./layout/Accordion/Accordion.svelte";
9
+ export { default as Filler } from "./layout/Filler/Filler.svelte";
7
10
  export { default as Footer } from "./layout/Footer/Footer.svelte";
11
+ export { default as Grid } from "./layout/Grid/Grid.svelte";
8
12
  export { default as Header } from "./layout/Header/Header.svelte";
13
+ export { default as Hero } from "./layout/Hero/Hero.svelte";
14
+ export { default as List } from "./layout/List/List.svelte";
15
+ export { default as NavSection } from "./layout/NavSections/NavSection.svelte";
16
+ export { default as NavSections } from "./layout/NavSections/NavSections.svelte";
17
+ export { default as Scroller } from "./layout/Scroller/Scroller.svelte";
18
+ export { default as ScrollerSection } from "./layout/Scroller/ScrollerSection.svelte";
19
+ export { default as Section } from "./layout/Section/Section.svelte";
20
+ export { default as TitleBlock } from "./layout/TitleBlock/TitleBlock.svelte";
9
21
  export { default as Twisty } from "./layout/Twisty/Twisty.svelte";
10
22
 
11
23
  // Inputs
12
24
  export { default as Button } from "./inputs/Button/Button.svelte";
13
25
  export { default as Dropdown } from "./inputs/Dropdown/Dropdown.svelte";
14
- export { default as Em } from "./decorators/Em/Em.svelte";
15
26
  export { default as Input } from "./inputs/Input/Input.svelte";
16
27
  export { default as Select } from "./inputs/Select/Select.svelte";
17
28
  export { default as Textarea } from "./inputs/Textarea/Textarea.svelte";
29
+
30
+ // Decorators
31
+ export { default as Blockquote } from "./decorators/Blockquote/Blockquote.svelte";
32
+ export { default as Divider } from "./decorators/Divider/Divider.svelte";
33
+ export { default as Em } from "./decorators/Em/Em.svelte";
34
+
35
+ // Data visualisation
36
+ export { default as Table } from "./datavis/Table/Table.svelte";
@@ -0,0 +1,32 @@
1
+ <script>
2
+ import { onMount } from "svelte";
3
+
4
+ /**
5
+ * Type of list
6
+ * @type {"bullet"|"dash"|"number"|"bare"}
7
+ */
8
+ export let mode = "bullet"; // dash | bullet | number | bare
9
+
10
+ let el;
11
+
12
+ onMount(() => {
13
+ [...el.children].forEach((c) => {
14
+ if (c.nodeName === "LI") c.className = "ons-list__item";
15
+ });
16
+ });
17
+ </script>
18
+
19
+ {#if mode === "number"}
20
+ <ol class="ons-list" bind:this="{el}">
21
+ <slot />
22
+ </ol>
23
+ {:else}
24
+ <ul
25
+ class="ons-list"
26
+ class:ons-list--dashed="{mode === 'dash'}"
27
+ class:ons-list--bare="{mode === 'bare'}"
28
+ bind:this="{el}"
29
+ >
30
+ <slot />
31
+ </ul>
32
+ {/if}
@@ -0,0 +1,51 @@
1
+ <script>
2
+ import { onMount, onDestroy, getContext } from "svelte";
3
+ import { slugify } from "$lib/js/utils.js";
4
+ import SectionBacklink from "./SectionBacklink.svelte";
5
+
6
+ /**
7
+ * Sets the title of the section
8
+ * @type {string}
9
+ */
10
+ export let title = "Section title";
11
+ /**
12
+ * Sets the unique ID of the section (if not set, this will be slugified from the title)
13
+ * @type {string}
14
+ */
15
+ export let id = slugify(title);
16
+ /**
17
+ * Allows the h2 title tag for the section to be visually hidden
18
+ * @type {boolean}
19
+ */
20
+ export let hideTitle = false;
21
+
22
+ const sections = getContext("sections");
23
+ const observer = getContext("observer");
24
+ const tocId = getContext("tocId");
25
+
26
+ let section;
27
+
28
+ onMount(() => {
29
+ if (sections && observer) {
30
+ $sections = [...$sections, { title, id }];
31
+ $observer.observe(section);
32
+ }
33
+ });
34
+
35
+ onDestroy(() => {
36
+ if (sections && observer) {
37
+ $sections = $sections.filter((s) => s.id !== id);
38
+ $observer.unobserve(section);
39
+ }
40
+ });
41
+ </script>
42
+
43
+ <section id="{id}" aria-label="{title}" bind:this="{section}">
44
+ {#if title && !hideTitle}
45
+ <h2 class="ons-u-mt-xl ons-u-pb-no ons-u-pt-no">{title}</h2>
46
+ {/if}
47
+ <slot />
48
+ {#if tocId}
49
+ <SectionBacklink tocId="{tocId}" />
50
+ {/if}
51
+ </section>
@@ -0,0 +1,92 @@
1
+ <script>
2
+ import { onMount, setContext } from "svelte";
3
+ import { writable } from "svelte/store";
4
+
5
+ /**
6
+ * A label for the page contents nav
7
+ * @type {string}
8
+ */
9
+ export let contentsLabel = "Page contents";
10
+ /**
11
+ * ID for contents nav section (for back links)
12
+ * @type {string}
13
+ */
14
+ export let tocId = "toc";
15
+ /**
16
+ * Don't include table of contents (allows for custom uses of nav panel)
17
+ * @type {boolean}
18
+ */
19
+ export let noContents = false;
20
+
21
+ let active;
22
+
23
+ setContext("tocId", tocId);
24
+
25
+ const sections = writable([]);
26
+ setContext("sections", sections);
27
+
28
+ const observer = writable();
29
+ setContext("observer", observer);
30
+
31
+ onMount(() => {
32
+ if (!noContents) {
33
+ $observer = new IntersectionObserver(
34
+ (entries, observer) => {
35
+ for (let i = 0; i < entries.length; i++) {
36
+ if (entries[i].isIntersecting) {
37
+ active = entries[i].target.id;
38
+ break;
39
+ }
40
+ }
41
+ },
42
+ {
43
+ root: null,
44
+ rootMargin: `0% 0% -70% 0%`,
45
+ threshold: 0,
46
+ }
47
+ );
48
+ }
49
+ });
50
+ </script>
51
+
52
+ <div class="ons-page__container ons-container">
53
+ <div class="ons-grid ons-js-toc-container ons-u-ml-no">
54
+ <slot name="header" />
55
+ <div class="ons-grid__col ons-col-4@m ons-u-pl-no ons-grid__col--sticky@m" id="{tocId}">
56
+ <aside class="ons-toc-container" role="complementary">
57
+ <nav class="ons-toc" aria-label="Pages in this guide">
58
+ <slot name="before-nav" />
59
+ {#if !noContents}
60
+ {#if contentsLabel}
61
+ <h2 class="ons-toc__title ons-u-fs-r--b ons-u-mb-s">
62
+ {contentsLabel}
63
+ </h2>
64
+ {/if}
65
+ <ol class="ons-list ons-u-mb-m ons-list--dashed">
66
+ {#each $sections as section}
67
+ <li class="ons-list__item">
68
+ <a
69
+ href="#{section.id}"
70
+ class="ons-list__link"
71
+ class:ons-toc__link-active="{section.id === active}"
72
+ >
73
+ {section.title}
74
+ </a>
75
+ </li>
76
+ {/each}
77
+ </ol>
78
+ {/if}
79
+ <slot name="after-nav" />
80
+ </nav>
81
+ </aside>
82
+ </div>
83
+ <div class="ons-grid__col ons-col-8@m ons-u-pl-no">
84
+ <slot name="before" />
85
+ {#if $observer}
86
+ <slot />
87
+ {/if}
88
+ <slot name="after" />
89
+ </div>
90
+ <slot name="footer" />
91
+ </div>
92
+ </div>
@@ -0,0 +1,31 @@
1
+ <script>
2
+ /**
3
+ * ID for contents nav section (for back links)
4
+ * @type {string}
5
+ */
6
+ export let tocId = "toc";
7
+ </script>
8
+
9
+ <div class="ons-u-mt-l ons-u-d-no@m">
10
+ <div class="ons-back-to">
11
+ <a href="#{tocId}" class="ons-back-to__link">
12
+ <span class="ons-back-to__icon"
13
+ ><svg
14
+ class="ons-svg-icon ons-u-mr-xs"
15
+ width="16"
16
+ height="17"
17
+ viewBox="0 0 16 17"
18
+ fill="none"
19
+ xmlns="http://www.w3.org/2000/svg"
20
+ focusable="false"
21
+ aria-hidden="true"
22
+ role="presentation"
23
+ >
24
+ <path
25
+ d="M0 8.07275L1.41 9.48275L7 3.90275V16.0728H9V3.90275L14.58 9.49275L16 8.07275L8 0.0727539L0 8.07275Z"
26
+ fill="currentColor"></path>
27
+ </svg>
28
+ </span>Back to contents</a
29
+ >
30
+ </div>
31
+ </div>
@@ -0,0 +1,97 @@
1
+ <script>
2
+ import Container from "$lib/wrappers/Container/Container.svelte";
3
+ import Meta from "./Meta.svelte";
4
+
5
+ /**
6
+ * Sets the title/headline
7
+ * @type {string}
8
+ */
9
+ export let title = "Page title";
10
+ /**
11
+ * Include "national statistic" badge
12
+ * @type {boolean}
13
+ */
14
+ export let natStatBadge = false;
15
+ /**
16
+ * Include Census logo
17
+ * @type {boolean}
18
+ */
19
+ export let censusLogo = false;
20
+ /**
21
+ * Array of {key, value} objects containing page metadata
22
+ * @type {array}
23
+ */
24
+ export let meta = [];
25
+ /**
26
+ * Sets a predefined theme
27
+ * @type {"light"|"dark"|"lightblue"}
28
+ */
29
+ export let theme = null;
30
+ /**
31
+ * Define additional props to override the base theme
32
+ * @type {object}
33
+ */
34
+ export let themeOverrides = null;
35
+ /**
36
+ * Overrides the background CSS for the section
37
+ * @type {string}
38
+ */
39
+ export let background = null;
40
+ </script>
41
+
42
+ <Container theme="{theme}" themeOverrides="{themeOverrides}" background="{background}">
43
+ <section class="ons-u-mb-xl">
44
+ <slot name="before" />
45
+ <div class="ons-grid">
46
+ <div class="ons-grid__col ons-col-10@m">
47
+ <h1 class="ons-u-fs-xxxl ons-u-mt-s ons-u-mb-m ons-u-pb-no ons-u-pt-no">
48
+ {title}
49
+ </h1>
50
+ </div>
51
+ {#if natStatBadge}
52
+ <div class="ons-grid__col ons-col-2@m">
53
+ <div
54
+ class="ons-grid--flex ons-grid--between@m ons-u-mt-s@m ons-u-mb-m@xxs ons-u-flex-jc-fe@m"
55
+ >
56
+ <a
57
+ href="https://uksa.statisticsauthority.gov.uk/about-the-authority/uk-statistical-system/types-of-official-statistics/"
58
+ class="national-statistics__link ons-u-fs-xxxl"
59
+ >
60
+ <img
61
+ src="//cdn.ons.gov.uk/assets/images/ons-logo/kitemark/uksa-kitemark.svg"
62
+ alt="UK Statistics Authority Kitemark"
63
+ class="national-statistics__logo"
64
+ />
65
+ </a>
66
+ </div>
67
+ </div>
68
+ {/if}
69
+ </div>
70
+ <slot name="brand" />
71
+ {#if censusLogo}
72
+ <div class="ons-grid ons-u-mb-m">
73
+ <div class="ons-grid__col">
74
+ <img
75
+ src="https://cdn.ons.gov.uk/assets/images/census-logo/logo-census-2021-purple-landscape.svg"
76
+ title="Census 2021"
77
+ alt="Census 2021"
78
+ class="header__svg-logo margin-right--1"
79
+ focusable="false"
80
+ width="167"
81
+ height="32"
82
+ />
83
+ </div>
84
+ </div>
85
+ {/if}
86
+ <Meta meta="{meta}" />
87
+ <slot name="after" />
88
+ </section>
89
+ </Container>
90
+
91
+ <style>
92
+ /* :global(.ons-page__container) {
93
+ overflow: auto;
94
+ } */
95
+ .ons-grid__col {
96
+ vertical-align: bottom;
97
+ }</style>
@@ -13,9 +13,11 @@
13
13
  });
14
14
  </script>
15
15
 
16
- <slot />
16
+ <div class="embed-container" style:display="content">
17
+ <slot />
18
+ </div>
17
19
 
18
20
  <style>
19
- :global(.ons-container) {
21
+ .embed-container :global(.ons-container) {
20
22
  padding: 0 !important;
21
23
  }</style>
@@ -56,7 +56,7 @@
56
56
  </svelte:head>
57
57
 
58
58
  {#if style}
59
- <div class="theme-wrapper" style="{style}">
59
+ <div class="theme-wrapper" style="{style}" style:display="content">
60
60
  <slot />
61
61
  </div>
62
62
  {:else}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",
@@ -116,7 +116,9 @@
116
116
  "./actions/cssVariables": "./dist/actions/cssVariables/index.js",
117
117
  "./actions/resizeObserver": "./dist/actions/resizeObserver/index.js",
118
118
  "./css/main.css": "./dist/css/main.css",
119
+ "./datavis/Table/Table.svelte": "./dist/datavis/Table/Table.svelte",
119
120
  "./decorators/Blockquote/Blockquote.svelte": "./dist/decorators/Blockquote/Blockquote.svelte",
121
+ "./decorators/Divider/Divider.svelte": "./dist/decorators/Divider/Divider.svelte",
120
122
  "./decorators/Em/Em.svelte": "./dist/decorators/Em/Em.svelte",
121
123
  "./globals.d.ts": "./dist/globals.d.ts",
122
124
  "./inputs/Button/Button.svelte": "./dist/inputs/Button/Button.svelte",
@@ -130,7 +132,6 @@
130
132
  "./js/withParams": "./dist/js/withParams.js",
131
133
  "./layout/Accordion/Accordion.svelte": "./dist/layout/Accordion/Accordion.svelte",
132
134
  "./layout/Accordion/AccordionItem.svelte": "./dist/layout/Accordion/AccordionItem.svelte",
133
- "./layout/Divider/Divider.svelte": "./dist/layout/Divider/Divider.svelte",
134
135
  "./layout/Filler/Filler.svelte": "./dist/layout/Filler/Filler.svelte",
135
136
  "./layout/Footer/Footer.svelte": "./dist/layout/Footer/Footer.svelte",
136
137
  "./layout/Footer/ONSLogo.svelte": "./dist/layout/Footer/ONSLogo.svelte",
@@ -138,6 +139,10 @@
138
139
  "./layout/Header/Header.svelte": "./dist/layout/Header/Header.svelte",
139
140
  "./layout/Header/ONSLogo.svelte": "./dist/layout/Header/ONSLogo.svelte",
140
141
  "./layout/Hero/Hero.svelte": "./dist/layout/Hero/Hero.svelte",
142
+ "./layout/List/List.svelte": "./dist/layout/List/List.svelte",
143
+ "./layout/NavSections/NavSection.svelte": "./dist/layout/NavSections/NavSection.svelte",
144
+ "./layout/NavSections/NavSections.svelte": "./dist/layout/NavSections/NavSections.svelte",
145
+ "./layout/NavSections/SectionBacklink.svelte": "./dist/layout/NavSections/SectionBacklink.svelte",
141
146
  "./layout/Scroller/Scroller.svelte": "./dist/layout/Scroller/Scroller.svelte",
142
147
  "./layout/Scroller/ScrollerSection.svelte": "./dist/layout/Scroller/ScrollerSection.svelte",
143
148
  "./layout/Section/Section.svelte": "./dist/layout/Section/Section.svelte",