@statistikzh/leu 0.14.0 → 0.14.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 (131) hide show
  1. package/.storybook/preview.js +11 -0
  2. package/CHANGELOG.md +18 -0
  3. package/README.md +0 -67
  4. package/dist/Accordion.d.ts +1 -1
  5. package/dist/Accordion.d.ts.map +1 -1
  6. package/dist/Accordion.js +7 -5
  7. package/dist/Button.d.ts +1 -1
  8. package/dist/Button.js +2 -2
  9. package/dist/ButtonGroup.d.ts +1 -1
  10. package/dist/ButtonGroup.js +1 -1
  11. package/dist/Checkbox.d.ts +1 -1
  12. package/dist/Checkbox.js +1 -1
  13. package/dist/CheckboxGroup.d.ts +1 -1
  14. package/dist/CheckboxGroup.js +1 -1
  15. package/dist/Chip.d.ts +1 -1
  16. package/dist/Chip.js +1 -1
  17. package/dist/ChipGroup.d.ts +1 -1
  18. package/dist/ChipGroup.js +1 -1
  19. package/dist/ChipLink.js +1 -1
  20. package/dist/ChipRemovable.js +1 -1
  21. package/dist/ChipSelectable.js +1 -1
  22. package/dist/Dialog.d.ts +1 -1
  23. package/dist/Dialog.js +2 -2
  24. package/dist/Dropdown.d.ts +1 -1
  25. package/dist/Dropdown.js +2 -2
  26. package/dist/Icon.d.ts +1 -1
  27. package/dist/Icon.js +1 -1
  28. package/dist/Input.d.ts +2 -2
  29. package/dist/Input.d.ts.map +1 -1
  30. package/dist/Input.js +4 -5
  31. package/dist/{LeuElement-BjGpKQpe.d.ts → LeuElement-BI1CxItv.d.ts} +1 -1
  32. package/dist/LeuElement-BI1CxItv.d.ts.map +1 -0
  33. package/dist/{LeuElement-BjGpKQpe.js → LeuElement-BI1CxItv.js} +1 -1
  34. package/dist/Menu.d.ts +1 -1
  35. package/dist/Menu.js +1 -1
  36. package/dist/MenuItem.d.ts +1 -1
  37. package/dist/MenuItem.js +1 -1
  38. package/dist/Pagination.d.ts +1 -1
  39. package/dist/Pagination.js +2 -2
  40. package/dist/Popup.d.ts +1 -1
  41. package/dist/Popup.js +1 -1
  42. package/dist/Radio.d.ts +1 -1
  43. package/dist/Radio.js +1 -1
  44. package/dist/RadioGroup.d.ts +1 -1
  45. package/dist/RadioGroup.js +1 -1
  46. package/dist/Range.d.ts +1 -1
  47. package/dist/Range.js +1 -1
  48. package/dist/ScrollTop.d.ts +1 -1
  49. package/dist/ScrollTop.js +2 -2
  50. package/dist/Select.d.ts +1 -5
  51. package/dist/Select.d.ts.map +1 -1
  52. package/dist/Select.js +3 -16
  53. package/dist/Spinner.d.ts +1 -1
  54. package/dist/Spinner.js +1 -1
  55. package/dist/Table.d.ts +1 -1
  56. package/dist/Table.js +2 -2
  57. package/dist/VisuallyHidden.d.ts +1 -1
  58. package/dist/VisuallyHidden.js +1 -1
  59. package/dist/{hasSlotController-DvFw2NdC.d.ts → hasSlotController-CCPfIEw1.d.ts} +1 -1
  60. package/dist/{hasSlotController-DvFw2NdC.d.ts.map → hasSlotController-CCPfIEw1.d.ts.map} +1 -1
  61. package/dist/{hasSlotController-DvFw2NdC.js → hasSlotController-CCPfIEw1.js} +1 -1
  62. package/dist/index.d.ts +1 -1
  63. package/dist/index.js +2 -2
  64. package/dist/leu-accordion.js +1 -1
  65. package/dist/leu-button-group.js +1 -1
  66. package/dist/leu-button.js +2 -2
  67. package/dist/leu-checkbox-group.js +1 -1
  68. package/dist/leu-checkbox.js +1 -1
  69. package/dist/leu-chip-group.js +1 -1
  70. package/dist/leu-chip-link.js +1 -1
  71. package/dist/leu-chip-removable.js +1 -1
  72. package/dist/leu-chip-selectable.js +1 -1
  73. package/dist/leu-dialog.js +2 -2
  74. package/dist/leu-dropdown.js +2 -2
  75. package/dist/leu-icon.js +1 -1
  76. package/dist/leu-input.js +1 -1
  77. package/dist/leu-menu-item.js +1 -1
  78. package/dist/leu-menu.js +1 -1
  79. package/dist/leu-pagination.js +2 -2
  80. package/dist/leu-popup.js +1 -1
  81. package/dist/leu-radio-group.js +1 -1
  82. package/dist/leu-radio.js +1 -1
  83. package/dist/leu-range.js +1 -1
  84. package/dist/leu-scroll-top.js +2 -2
  85. package/dist/leu-select.js +2 -2
  86. package/dist/leu-spinner.js +1 -1
  87. package/dist/leu-table.js +2 -2
  88. package/dist/leu-visually-hidden.js +1 -1
  89. package/dist/theme.css +4 -4
  90. package/dist/vscode.html-custom-data.json +1 -1
  91. package/dist/vue/index.d.ts +0 -1
  92. package/dist/web-types.json +2 -2
  93. package/package.json +3 -3
  94. package/scripts/generate-component/templates/stories/[name].stories.js +1 -1
  95. package/src/components/accordion/Accordion.js +1 -1
  96. package/src/components/accordion/accordion.css +6 -3
  97. package/src/components/accordion/stories/accordion.stories.js +7 -6
  98. package/src/components/button/stories/button.stories.js +1 -1
  99. package/src/components/button-group/stories/button-group.stories.js +1 -1
  100. package/src/components/checkbox/stories/checkbox-group.stories.js +1 -1
  101. package/src/components/checkbox/stories/checkbox.stories.js +1 -1
  102. package/src/components/chip/stories/chip-group.stories.js +1 -1
  103. package/src/components/chip/stories/chip-link.stories.js +1 -1
  104. package/src/components/chip/stories/chip-removable.stories.js +1 -1
  105. package/src/components/chip/stories/chip-selectable.stories.js +1 -1
  106. package/src/components/dialog/stories/dialog.stories.js +1 -1
  107. package/src/components/dropdown/stories/dropdown.stories.js +1 -1
  108. package/src/components/icon/stories/icon.stories.js +1 -1
  109. package/src/components/input/Input.js +1 -1
  110. package/src/components/input/input.css +2 -2
  111. package/src/components/input/stories/input.stories.js +1 -2
  112. package/src/components/menu/stories/menu-item.stories.js +1 -1
  113. package/src/components/menu/stories/menu.stories.js +1 -1
  114. package/src/components/pagination/stories/pagination.stories.js +1 -1
  115. package/src/components/popup/stories/popup.stories.js +1 -1
  116. package/src/components/radio/stories/radio-group.stories.js +1 -1
  117. package/src/components/radio/stories/radio.stories.js +1 -1
  118. package/src/components/range/stories/range-slider.stories.js +1 -1
  119. package/src/components/scroll-top/stories/scroll-top.stories.js +1 -1
  120. package/src/components/select/Select.js +1 -17
  121. package/src/components/select/stories/select.stories.js +2 -2
  122. package/src/components/spinner/stories/spinner.stories.js +1 -1
  123. package/src/components/table/stories/table.stories.js +1 -1
  124. package/src/components/visually-hidden/stories/visually-hidden.stories.js +1 -1
  125. package/src/docs/contributing.mdx +154 -0
  126. package/src/docs/installation.mdx +35 -0
  127. package/src/docs/theme.mdx +349 -0
  128. package/src/docs/usage.mdx +73 -0
  129. package/src/styles/custom-properties.css +4 -4
  130. package/src/styles/style.stories.js +1 -1
  131. package/dist/LeuElement-BjGpKQpe.d.ts.map +0 -1
@@ -4,7 +4,7 @@ import { action } from "@storybook/addon-actions"
4
4
  import "../leu-chip-removable.js"
5
5
 
6
6
  export default {
7
- title: "Chip/Removable",
7
+ title: "Components/Chip/Removable",
8
8
  component: "leu-chip-removable",
9
9
  args: {
10
10
  label: "Daten",
@@ -6,7 +6,7 @@ import "../leu-chip-selectable.js"
6
6
  import { SIZES, VARIANTS } from "../ChipSelectable.js"
7
7
 
8
8
  export default {
9
- title: "Chip/Selectable",
9
+ title: "Components/Chip/Selectable",
10
10
  component: "leu-chip-selectable",
11
11
  argTypes: {
12
12
  variant: { control: "select", options: Object.values(VARIANTS) },
@@ -4,7 +4,7 @@ import "../../input/leu-input.js"
4
4
  import "../../button/leu-button.js"
5
5
 
6
6
  export default {
7
- title: "Dialog",
7
+ title: "Components/Dialog",
8
8
  component: "leu-dialog",
9
9
  parameters: {
10
10
  design: {
@@ -8,7 +8,7 @@ import { paths as iconPaths } from "../../icon/paths.js"
8
8
  * @type {import("@storybook/web-components").Meta}
9
9
  */
10
10
  export default {
11
- title: "Dropdown",
11
+ title: "Components/Dropdown",
12
12
  component: "leu-dropdown",
13
13
  parameters: {
14
14
  design: {
@@ -4,7 +4,7 @@ import { ifDefined } from "lit/directives/if-defined.js"
4
4
  import { paths } from "../paths.js"
5
5
 
6
6
  export default {
7
- title: "Icon",
7
+ title: "Components/Icon",
8
8
  component: "leu-icon",
9
9
  argTypes: {
10
10
  name: {
@@ -171,7 +171,7 @@ export class LeuInput extends LeuElement {
171
171
  * Method for handling the blur event of the input element.
172
172
  * Checks validity of the input element and sets the validity state.
173
173
  * @private
174
- * @param {FocusEvent} event
174
+ * @param {FocusEvent & {target: HTMLInputElement}} event
175
175
  * @returns {void}
176
176
  */
177
177
  handleBlur(event) {
@@ -95,8 +95,8 @@
95
95
 
96
96
  .prefix,
97
97
  .suffix {
98
- padding-block: 2rem 1rem;
99
-
98
+ padding-block: calc(2rem - var(--input-border-width))
99
+ calc(1rem - var(--input-border-width));
100
100
  font-size: 1rem;
101
101
  line-height: 1.5;
102
102
  color: var(--input-affix-color);
@@ -7,9 +7,8 @@ import { SIZES } from "../Input.js"
7
7
  import { paths as iconPaths } from "../../icon/paths.js"
8
8
 
9
9
  export default {
10
- title: "Input",
10
+ title: "Components/Input",
11
11
  component: "leu-input",
12
- tags: ["autodocs"],
13
12
  argTypes: {
14
13
  size: {
15
14
  control: {
@@ -10,7 +10,7 @@ function isIcon(name) {
10
10
  }
11
11
 
12
12
  export default {
13
- title: "Menu/Item",
13
+ title: "Components/Menu/Item",
14
14
  component: "leu-menu-item",
15
15
  args: {
16
16
  label: "Menu Item",
@@ -5,7 +5,7 @@ import "../../icon/leu-icon.js"
5
5
  import { ifDefined } from "lit/directives/if-defined.js"
6
6
 
7
7
  export default {
8
- title: "Menu",
8
+ title: "Components/Menu",
9
9
  component: "leu-menu",
10
10
  parameters: {
11
11
  design: {
@@ -58,7 +58,7 @@ const items = [
58
58
  ]
59
59
 
60
60
  export default {
61
- title: "Pagination",
61
+ title: "Components/Pagination",
62
62
  component: "leu-pagination",
63
63
  args: {
64
64
  onPageChange: action("leu:pagechange"),
@@ -5,7 +5,7 @@ import "../leu-popup.js"
5
5
  import "../../button/leu-button.js"
6
6
 
7
7
  export default {
8
- title: "Popup",
8
+ title: "Components/Popup",
9
9
  component: "leu-popup",
10
10
  argTypes: {
11
11
  placement: {
@@ -4,7 +4,7 @@ import "../leu-radio-group.js"
4
4
  import { ifDefined } from "lit/directives/if-defined.js"
5
5
 
6
6
  export default {
7
- title: "Radio/Group",
7
+ title: "Components/Radio/Group",
8
8
  component: "leu-radio-group",
9
9
  argTypes: {
10
10
  label: { control: "text" },
@@ -2,7 +2,7 @@ import { html } from "lit"
2
2
  import "../leu-radio.js"
3
3
 
4
4
  export default {
5
- title: "Radio",
5
+ title: "Components/Radio",
6
6
  component: "leu-radio",
7
7
  argTypes: {
8
8
  label: {
@@ -8,7 +8,7 @@ import "../../input/leu-input.js"
8
8
  * @type {import("@storybook/web-components").Meta}
9
9
  */
10
10
  export default {
11
- title: "Range",
11
+ title: "Components/Range",
12
12
  component: "leu-range",
13
13
  parameters: {
14
14
  design: {
@@ -2,7 +2,7 @@ import { html } from "lit"
2
2
  import "../leu-scroll-top.js"
3
3
 
4
4
  export default {
5
- title: "ScrollTop",
5
+ title: "Components/ScrollTop",
6
6
  component: "leu-scroll-top",
7
7
  }
8
8
 
@@ -356,18 +356,6 @@ export class LeuSelect extends LeuElement {
356
356
  }
357
357
  }
358
358
 
359
- /**
360
- * Close the dropdown if the focus moves outside the component.
361
- */
362
- _handlePopupFocusOut(event) {
363
- if (
364
- !this.contains(event.relatedTarget) &&
365
- !this.shadowRoot.contains(event.relatedTarget)
366
- ) {
367
- this._closeDropdown()
368
- }
369
- }
370
-
371
359
  _renderFilterInput() {
372
360
  if (this.filterable) {
373
361
  return html` <leu-input
@@ -467,11 +455,7 @@ export class LeuSelect extends LeuElement {
467
455
  autoSizePadding="8"
468
456
  >
469
457
  ${this._renderToggleButton()}
470
- <div
471
- id="select-popup"
472
- class="select-menu-container"
473
- @focusout=${this._handlePopupFocusOut}
474
- >
458
+ <div id="select-popup" class="select-menu-container">
475
459
  <slot name="before" class="before"></slot>
476
460
  ${this._renderFilterInput()}
477
461
  <leu-menu
@@ -8,7 +8,7 @@ import "../../menu/leu-menu-item.js"
8
8
  import { MUNICIPALITIES } from "../test/fixtures.js"
9
9
 
10
10
  export default {
11
- title: "Select",
11
+ title: "Components/Select",
12
12
  component: "leu-select",
13
13
  parameters: {
14
14
  design: {
@@ -68,7 +68,7 @@ function Template({
68
68
 
69
69
  function TemplateSlots(args) {
70
70
  const before = html`<div>before</div>`
71
- const after = html`<div>after <input type="text"></input></div>`
71
+ const after = html`<div>after <input type="text" /></div>`
72
72
 
73
73
  return Template({ ...args, before, after })
74
74
  }
@@ -3,7 +3,7 @@ import "../leu-spinner.js"
3
3
  import { styleMap } from "lit/directives/style-map.js"
4
4
 
5
5
  export default {
6
- title: "Spinner",
6
+ title: "Components/Spinner",
7
7
  component: "leu-spinner",
8
8
  argTypes: {
9
9
  color: {
@@ -2,7 +2,7 @@ import { html } from "lit"
2
2
  import "../leu-table.js"
3
3
 
4
4
  export default {
5
- title: "Table",
5
+ title: "Components/Table",
6
6
  component: "leu-table",
7
7
  parameters: {
8
8
  design: {
@@ -2,7 +2,7 @@ import { html } from "lit"
2
2
  import "../leu-visually-hidden.js"
3
3
 
4
4
  export default {
5
- title: "VisuallyHidden",
5
+ title: "Components/VisuallyHidden",
6
6
  component: "leu-visually-hidden",
7
7
  argTypes: {
8
8
  content: {
@@ -0,0 +1,154 @@
1
+ import { Meta, Markdown } from "@storybook/blocks"
2
+
3
+ <Meta title="Introduction/Contributing" />
4
+
5
+ # Contributing
6
+
7
+ Contributing to this project is highly appreciated. We are happy to receive feedback, bug reports, feature requests, and pull requests.
8
+
9
+ ## Web compenents
10
+
11
+ Leu is entirely built with the lit library and custom elements.
12
+ If you haven't worked with either of them before, [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements) has a good introduction to custom elements.
13
+ The [lit documentation](https://lit.dev/docs/) is a good starting point to get to know the library.
14
+
15
+ ## Create a new component
16
+
17
+ To create a starting point for a new component, run
18
+
19
+ ```bash
20
+ ./scripts/generate-component/generate.js
21
+ ```
22
+
23
+ Running it with `--help` will show you all available options.
24
+
25
+ It creates a basic structure for a new component in the `src/components` directory.
26
+
27
+ ## Linting and formatting
28
+
29
+ This project uses eslint and prettier to lint and format the code.
30
+ commitlint is also used the enforce conventional commit messages.
31
+
32
+ To scan the project for linting and formatting errors, run
33
+
34
+ ```bash
35
+ npm run lint
36
+ ```
37
+
38
+ To automatically fix linting and formatting errors, run
39
+
40
+ ```bash
41
+ npm run format
42
+ ```
43
+
44
+ ## Testing with Web Test Runner
45
+
46
+ To execute a single test run:
47
+
48
+ ```bash
49
+ npm run test
50
+ ```
51
+
52
+ To run the tests in interactive watch mode run:
53
+
54
+ ```bash
55
+ npm run test:watch
56
+ ```
57
+
58
+ ## Demoing with Storybook
59
+
60
+ To run a local instance of Storybook for your component, run
61
+
62
+ ```bash
63
+ npm run storybook
64
+ ```
65
+
66
+ ## Development guidelines
67
+
68
+ A few rules are necessary when developing a component library. The following conventions and guidelines should be followed when new features are implemented.
69
+
70
+ At the same time they're not set in stone. If the there is a good reason to change them open a pull request.
71
+
72
+ ### Naming
73
+
74
+ Every element or custom property that will be globally available has to be prefixed with `leu`.
75
+
76
+ ```js
77
+ /* Custom elements */
78
+ class LeuRadio extends LeuElement {
79
+ ...
80
+ }
81
+
82
+ window.customElements.define("leu-input", LeuInput)
83
+ ```
84
+
85
+ ```css
86
+ /* CSS custom property of the theme */
87
+ :root {
88
+ --leu-color-black-0: #000;
89
+ }
90
+ ```
91
+
92
+ ### Scoped styles
93
+
94
+ All CSS declarations have to live inside a custom element. This way we ensure that the styles won't interfere with the environment they're loaded into.
95
+ Styles that are shared between components should be defined as global custom properties inside the `styles/custom-properties.css`.
96
+ When a global custom property is used inside a component it could be a good practice to assign them to a local custom property with a semantic naming.
97
+ This only make a sense when the component has a certain complexity and the global custom property are used multiple times.
98
+
99
+ ```css
100
+ :host {
101
+ --radio-color-disabled: var(--leu-color-black-20);
102
+ }
103
+ ```
104
+
105
+ ### Value property
106
+
107
+ All custom elements that contain a value of some sort (like an input or select fields) have to implement a `value` property.
108
+ Everytime the value of the `value` property changes a `input` event has to be dispatched.
109
+ This behaviour matches the way [Observable](https://observablehq.com) handles and observes changes of values that are contained in arbitrary elements. We decided to take over this pattern as it is usable in every other environment too.
110
+
111
+ ### Custom events
112
+
113
+ Name of custom events have to be prefixed with `leu:`.
114
+
115
+ ```js
116
+ this.dispatchEvent(new Event("leu:select", { bubbles: true, composed: true }))
117
+ ```
118
+
119
+ ### Dependencies
120
+
121
+ We try to use as little non-dev dependencies as possible. The following dependencies are used:
122
+
123
+ - `lit` is used to build all components.
124
+ - `@floating-ui/dom` is used to position tooltips etc.
125
+
126
+ ### Composability
127
+
128
+ Components should be composable. This means that it should be possible to use them in combination with other components without any problems.
129
+ It can also make sense to split a component into multiple smaller components.
130
+
131
+ The `leu-dropdown` element is a good example for this.
132
+
133
+ ```html
134
+ <leu-dropdown label="Download">
135
+ <leu-menu>
136
+ <leu-menu-item>PDF</leu-menu-item>
137
+ <leu-menu-item>CSV</leu-menu-item>
138
+ <leu-menu-item>Excel</leu-menu-item>
139
+ </leu-menu>
140
+ </leu-dropdown>
141
+ ```
142
+
143
+ It could've been built as a single element by passing data to a property. The component could then render the menu and the menu items itself inside the shadow dom.
144
+
145
+ ```js
146
+ html`<leu-dropdown
147
+ label="Download"
148
+ .items=${["PDF", "CSV", "Excel"]}
149
+ ></leu-dropdown>`
150
+ ```
151
+
152
+ But this approach would make it impossible to create and populate the element with only HTML. It also is much harderß to apply event listeners or custom attributes like `role` to specific child elements.
153
+
154
+ The `leu-table` element is (currently) built like that and shouldn't be used as an example for composability.
@@ -0,0 +1,35 @@
1
+ import { Meta, Markdown } from "@storybook/blocks"
2
+
3
+ <Meta title="Introduction/Installation" />
4
+
5
+ # Installation
6
+
7
+ You can load the leu library from a CDN or install it via npm.
8
+
9
+ ## npm installation
10
+
11
+ For most projects, you will want to install the library via npm.
12
+
13
+ ```bash
14
+ npm i @statistikzh/leu
15
+ ```
16
+
17
+ ## CDN
18
+
19
+ If you are in you're just using plain HTML and JavaScript without any build or transformation steps or just want to tinker around with the library, you can use a CDN.
20
+ Browsers can't resolve bare module imports without import maps. But we can use a CDN like esm.sh to resolve the imports for us.
21
+ This is also applicable in an environment like [Observable](https://observablehq.com).
22
+
23
+ If you're using this approach, **always** define the version you want to use. This way you can ensure that your application doesn't break when a new version is released.
24
+
25
+ > ⚠️ Be aware that most CDN (including esm.sh) are probably not GDPR compliant. Don't use this approach in a production environment.
26
+
27
+ ```html
28
+ <link
29
+ rel="stylesheet"
30
+ href="https://esm.sh/@statistikzh/leu@0.13.1/dist/theme.css"
31
+ />
32
+ <script type="module">
33
+ import "https://esm.sh/@statistikzh/leu@0.13.1/dist/leu-input.js"
34
+ </script>
35
+ ```