@bonniernews/dn-design-system-web 22.2.3 → 22.3.0
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/CHANGELOG.md +7 -0
- package/components/button/README.md +3 -3
- package/components/button-toggle/README.md +1 -1
- package/components/checkbox/README-NJK.md +43 -0
- package/components/checkbox/README.md +26 -43
- package/components/divider/README.md +1 -1
- package/components/icon-button/README.md +1 -1
- package/components/icon-button-toggle/README.md +1 -1
- package/components/list-item/list-item-types.ts +113 -0
- package/components/list-item/list-item.js +1 -1
- package/components/radio-button/README-NJK.md +49 -0
- package/components/radio-button/README.md +35 -49
- package/components/switch/README-NJK.md +42 -0
- package/components/switch/README.md +28 -42
- package/package.json +1 -1
- package/preact/assets/form-field/form-field.d.ts +12 -0
- package/preact/components/button/button-types.d.ts +73 -0
- package/preact/components/checkbox/checkbox.d.ts +23 -0
- package/preact/components/checkbox/checkbox.js +94 -0
- package/preact/components/checkbox/checkbox.js.map +7 -0
- package/preact/components/list-item/list-item-types.d.ts +82 -0
- package/preact/components/list-item/list-item.d.ts +2 -0
- package/preact/components/list-item/list-item.js +573 -0
- package/preact/components/list-item/list-item.js.map +7 -0
- package/preact/components/radio-button/radio-button.d.ts +30 -0
- package/preact/components/radio-button/radio-button.js +94 -0
- package/preact/components/radio-button/radio-button.js.map +7 -0
- package/preact/components/switch/switch.d.ts +26 -0
- package/preact/components/switch/switch.js +68 -0
- package/preact/components/switch/switch.js.map +7 -0
- package/preact/components/teaser-card/teaser-card.d.ts +2 -1
- package/preact/components/teaser-card/teaser-card.js.map +2 -2
- package/preact/components/teaser-onsite/teaser-onsite.js.map +2 -2
- package/tsconfig.json +2 -1
- /package/components/list-item/{README.md → README-NJK.md} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ All changes to @bonniernews/dn-design-system-web will be documented in this file
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
## [22.3.0](https://github.com/BonnierNews/dn-design-system/compare/@bonniernews/dn-design-system-web@22.2.3...@bonniernews/dn-design-system-web@22.3.0) (2025-01-08)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **web:** tsx list items and form components ([#1552](https://github.com/BonnierNews/dn-design-system/issues/1552)) ([cbab08f](https://github.com/BonnierNews/dn-design-system/commit/cbab08faddfa967921a6b4143066e0f37d7e9c48))
|
|
13
|
+
|
|
7
14
|
## [22.2.3](https://github.com/BonnierNews/dn-design-system/compare/@bonniernews/dn-design-system-web@22.2.2...@bonniernews/dn-design-system-web@22.2.3) (2024-12-20)
|
|
8
15
|
|
|
9
16
|
|
|
@@ -18,11 +18,11 @@ Button
|
|
|
18
18
|
| loading | boolean | false |
|
|
19
19
|
| iconName | add, arrow\_back, arrow\_forward etc | | For all available icons see: [https://designsystem.dn.se/?path=/story/foundations-icons--all-icons](https://designsystem.dn.se/?path=/story/foundations-icons--all-icons)<br />"add", "arrow\_back", "arrow\_forward", "arrow\_outward", "arrow\_upward", "bookmark-filled", "bookmarked", "campaign" | \- |
|
|
20
20
|
| variant | Design variant<br />"brand", "secondary", "primary", "staticWhite" | "primary" |
|
|
21
|
-
| emphasis | "default", "elevated", "outline", "transparent" | "default" |
|
|
22
|
-
| rounded | Button will be rounded<br />boolean | false |
|
|
23
|
-
| href | If href is set the button will be rendered as an a-tag<br />string | \- |
|
|
24
21
|
| fullWidth | Button will be full width on both desktop and mobile<br />boolean | false |
|
|
25
22
|
| mobileFullWidth | Button will only full width on mobile<br />boolean | false |
|
|
23
|
+
| href | If href is set the button will be rendered as an a-tag<br />string | \- |
|
|
24
|
+
| emphasis | "default", "elevated", "outline", "transparent" | "default" |
|
|
25
|
+
| rounded | Button will be rounded<br />boolean | false |
|
|
26
26
|
| iconPosition | "right", "none", "left" | "none" |
|
|
27
27
|
| type | "button", "submit" | "button" |
|
|
28
28
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
- GitHub: [BonnierNews/dn-design-system/../web/src/components/checkbox](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/checkbox)
|
|
2
|
+
- Storybook: [Form > Checkbox](https://designsystem.dn.se/?path=/docs/basic-form-checkbox--docs)
|
|
3
|
+
- Storybook (Latest): [Form > Checkbox](https://designsystem-latest.dn.se/?path=/docs/basic-form-checkbox--docs)
|
|
4
|
+
|
|
5
|
+
----
|
|
6
|
+
|
|
7
|
+
# Checkbox
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
|parameter | type | required | options | default | description |
|
|
12
|
+
|:--- | :--- | :--- | :--- | :--- | :--- |
|
|
13
|
+
|name | String | yes | | | Also used as id |
|
|
14
|
+
|label | String | no | | | |
|
|
15
|
+
|checked | bool | no | true, false | false | |
|
|
16
|
+
|disabled | bool | no | true, false | false | |
|
|
17
|
+
|error | bool | no | true, false | false | |
|
|
18
|
+
|errorMessage | String | no | | | |
|
|
19
|
+
|required | bool | no | true, false | false | |
|
|
20
|
+
|validation | String | no | | | To use with the sites validation, some example values for dn-web: required, password, email |
|
|
21
|
+
|attributes | Object | no | | | Ex. { target: "_blank", "data-test": "lorem ipsum" } |
|
|
22
|
+
|classNames | String | no | | | Ex. "my-special-class" |
|
|
23
|
+
|forcePx | bool | no | true, false | false | Fixed pixel value is used for typography to prevent scaling based on html font-size |
|
|
24
|
+
|
|
25
|
+
## Minimum requirement example
|
|
26
|
+
|
|
27
|
+
### Nunjucks
|
|
28
|
+
|
|
29
|
+
These are copy paste friendly examples to quickliy get started using a component.
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
{% from '@bonniernews/dn-design-system-web/components/checkbox/checkbox.njk' import Checkbox %}
|
|
33
|
+
|
|
34
|
+
{{ Checkbox({
|
|
35
|
+
label: 'My checkbox',
|
|
36
|
+
name: 'my-checkbox'
|
|
37
|
+
})}}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### SCSS
|
|
41
|
+
```scss
|
|
42
|
+
@use "@bonniernews/dn-design-system-web/components/checkbox/checkbox";
|
|
43
|
+
```
|
|
@@ -1,43 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
|
12
|
-
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|checked |
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Nunjucks
|
|
28
|
-
|
|
29
|
-
These are copy paste friendly examples to quickliy get started using a component.
|
|
30
|
-
|
|
31
|
-
```html
|
|
32
|
-
{% from '@bonniernews/dn-design-system-web/components/checkbox/checkbox.njk' import Checkbox %}
|
|
33
|
-
|
|
34
|
-
{{ Checkbox({
|
|
35
|
-
label: 'My checkbox',
|
|
36
|
-
name: 'my-checkbox'
|
|
37
|
-
})}}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### SCSS
|
|
41
|
-
```scss
|
|
42
|
-
@use "@bonniernews/dn-design-system-web/components/checkbox/checkbox";
|
|
43
|
-
```
|
|
1
|
+
Checkbox
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
* GitHub: [BonnierNews/dn-design-system/../web/src/components/checkbox](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/checkbox)
|
|
5
|
+
* Storybook: [Checkbox](https://designsystem.dn.se/?path=/docs/basic-form-checkbox--docs)
|
|
6
|
+
|
|
7
|
+
The component will not include styling by itself. Make sure to include the right styles for the component. See example below: `@use '@bonniernews/dn-design-system-web/components/checkbox/checkbox.scss`
|
|
8
|
+
|
|
9
|
+
| Name | Description | Default |
|
|
10
|
+
|:--- | :--- | :--- |
|
|
11
|
+
| error | boolean | \- |
|
|
12
|
+
| errorMessage | string | \- |
|
|
13
|
+
| label | string | \- |
|
|
14
|
+
| stripLabel | boolean | \- |
|
|
15
|
+
| checked | boolean | \- |
|
|
16
|
+
| required | boolean | \- |
|
|
17
|
+
| disabled | boolean | \- |
|
|
18
|
+
| name | string | "ds-checkbox" |
|
|
19
|
+
| validation | string | \- |
|
|
20
|
+
| classNames | string | \- |
|
|
21
|
+
| forcePx | boolean | \- |
|
|
22
|
+
| attributes | {} | \- |
|
|
23
|
+
|
|
24
|
+
```jsx
|
|
25
|
+
<Checkbox name="ds-checkbox" />
|
|
26
|
+
```
|
|
@@ -8,7 +8,7 @@ The component will not include styling by itself. Make sure to include the right
|
|
|
8
8
|
|
|
9
9
|
| Name | Description | Default |
|
|
10
10
|
|:--- | :--- | :--- |
|
|
11
|
-
| variant | "
|
|
11
|
+
| variant | "medium", "soft", "hard" | "soft" |
|
|
12
12
|
| classNames | string | \- |
|
|
13
13
|
| attributes | object | \- |
|
|
14
14
|
|
|
@@ -17,9 +17,9 @@ The component will not include styling by itself. Make sure to include the right
|
|
|
17
17
|
| size | "large", "small", "medium", "xlarge" | "medium" |
|
|
18
18
|
| loading | boolean | false |
|
|
19
19
|
| iconName | add, arrow\_back, arrow\_forward etc | | For all available icons see: [https://designsystem.dn.se/?path=/story/foundations-icons--all-icons](https://designsystem.dn.se/?path=/story/foundations-icons--all-icons)<br />"add", "arrow\_back", "arrow\_forward", "arrow\_outward", "arrow\_upward", "bookmark-filled", "bookmarked", "campaign" | \- |
|
|
20
|
+
| href | If href is set the button will be rendered as an a-tag<br />string | \- |
|
|
20
21
|
| emphasis | "default", "elevated", "outline", "transparent" | "default" |
|
|
21
22
|
| rounded | Button will be rounded<br />boolean | true |
|
|
22
|
-
| href | If href is set the button will be rendered as an a-tag<br />string | \- |
|
|
23
23
|
|
|
24
24
|
```jsx
|
|
25
25
|
<IconButton
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ComponentChildren } from "preact";
|
|
2
|
+
|
|
3
|
+
import { ButtonProps } from '../radio-button/radio-button'
|
|
4
|
+
import type { DsIcon } from '@bonniernews/dn-design-system-web/types-lib/ds-icon.d.ts'
|
|
5
|
+
import { SwitchInnerProps } from '../switch/switch'
|
|
6
|
+
import { ButtonToggleProps } from '../button/button-types'
|
|
7
|
+
|
|
8
|
+
export interface ListItemSharedProps {
|
|
9
|
+
title?: string
|
|
10
|
+
subtitle?: string
|
|
11
|
+
meta?: string
|
|
12
|
+
border?: boolean
|
|
13
|
+
fontWeight?: 'regular' | 'semibold' | 'bold'
|
|
14
|
+
attributes?: { [key: string]: string }
|
|
15
|
+
children?: ComponentChildren
|
|
16
|
+
forcePx?: boolean
|
|
17
|
+
classNames?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ListItemBaseProps extends ListItemSharedProps {
|
|
21
|
+
listItemType: 'accordion' | 'checkbox' | 'radio' | 'switch' | 'image' | 'byline' | 'standard' | 'toggle'
|
|
22
|
+
radioButtons?: ButtonProps[]
|
|
23
|
+
href?: string
|
|
24
|
+
leadingIcon?: DsIcon
|
|
25
|
+
trailingIcon?: DsIcon
|
|
26
|
+
mediaHtml?: string
|
|
27
|
+
name?: string
|
|
28
|
+
id?: string
|
|
29
|
+
value?: string
|
|
30
|
+
accordionContent?: any
|
|
31
|
+
checked?: boolean
|
|
32
|
+
selected?: boolean
|
|
33
|
+
stripLabel?: boolean
|
|
34
|
+
toggleText?: string
|
|
35
|
+
toggleSelectedText?: string
|
|
36
|
+
disabled?: boolean
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AccordionListItemProps
|
|
40
|
+
extends ListItemSharedProps,
|
|
41
|
+
Pick<ListItemBaseProps, 'accordionContent' | 'leadingIcon'> {}
|
|
42
|
+
|
|
43
|
+
export interface CheckboxListItemProps
|
|
44
|
+
extends ListItemSharedProps,
|
|
45
|
+
Pick<ListItemBaseProps, 'href' | 'name' | 'checked' | 'stripLabel' | 'disabled'> {}
|
|
46
|
+
|
|
47
|
+
export interface ImageListItemProps extends ListItemSharedProps, Pick<ListItemBaseProps, 'href' | 'trailingIcon'> {
|
|
48
|
+
mediaHtml: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface RadioListItemProps
|
|
52
|
+
extends ListItemSharedProps,
|
|
53
|
+
Pick<ListItemBaseProps, 'href' | 'name' | 'id' | 'selected' | 'stripLabel' | 'value' | 'disabled'> {
|
|
54
|
+
selected: boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface StandardListItemProps
|
|
58
|
+
extends ListItemSharedProps,
|
|
59
|
+
Pick<ListItemBaseProps, 'href' | 'leadingIcon' | 'trailingIcon'> {}
|
|
60
|
+
|
|
61
|
+
export interface SwitchListItemProps
|
|
62
|
+
extends ListItemSharedProps,
|
|
63
|
+
SwitchInnerProps,
|
|
64
|
+
Pick<ListItemBaseProps, 'leadingIcon' | 'disabled' | 'selected' | 'stripLabel' | 'value'> {
|
|
65
|
+
name: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ToggleListItemProps
|
|
69
|
+
extends ListItemSharedProps,
|
|
70
|
+
ButtonToggleProps,
|
|
71
|
+
Pick<ListItemBaseProps, 'title' | 'subtitle' | 'disabled' | 'selected'> {
|
|
72
|
+
name: string
|
|
73
|
+
titleHref?: string
|
|
74
|
+
toggleText: string
|
|
75
|
+
toggleSelectedText: string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface BylineListItemProps extends ToggleListItemProps, Pick<ListItemBaseProps, 'mediaHtml'> {}
|
|
79
|
+
|
|
80
|
+
export type ListItemProps =
|
|
81
|
+
| ({ listItemType: 'accordion' } & AccordionListItemProps)
|
|
82
|
+
| ({ listItemType: 'checkbox' } & CheckboxListItemProps)
|
|
83
|
+
| ({ listItemType: 'image' } & ImageListItemProps)
|
|
84
|
+
| ({ listItemType: 'radio' } & RadioListItemProps)
|
|
85
|
+
| ({ listItemType: 'standard' } & StandardListItemProps)
|
|
86
|
+
| ({ listItemType: 'switch' } & SwitchListItemProps)
|
|
87
|
+
| ({ listItemType: 'toggle' } & ToggleListItemProps)
|
|
88
|
+
| ({ listItemType: 'byline' } & BylineListItemProps)
|
|
89
|
+
|
|
90
|
+
export interface InnerListItemProps
|
|
91
|
+
extends ListItemSharedProps,
|
|
92
|
+
Pick<
|
|
93
|
+
ListItemBaseProps,
|
|
94
|
+
| 'listItemType'
|
|
95
|
+
| 'href'
|
|
96
|
+
| 'accordionContent'
|
|
97
|
+
| 'name'
|
|
98
|
+
| 'id'
|
|
99
|
+
| 'checked'
|
|
100
|
+
| 'selected'
|
|
101
|
+
| 'value'
|
|
102
|
+
| 'forcePx'
|
|
103
|
+
| 'toggleText'
|
|
104
|
+
| 'toggleSelectedText'
|
|
105
|
+
| 'disabled'
|
|
106
|
+
>,
|
|
107
|
+
Pick<ButtonToggleProps, 'variant'> {
|
|
108
|
+
componentClassName: string
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type TitleProps = Pick<ListItemBaseProps, 'title' | 'subtitle' | 'fontWeight' | 'attributes'> & {
|
|
112
|
+
componentClassName: string
|
|
113
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
- GitHub: [BonnierNews/dn-design-system/../web/src/components/radio-button](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/radio-button)
|
|
2
|
+
- Storybook: [Form > RadioButton](https://designsystem.dn.se/?path=/docs/basic-form-radiobutton--docs)
|
|
3
|
+
- Storybook (Latest): [Form > RadioButton](https://designsystem-latest.dn.se/?path=/docs/basic-form-radiobutton--docs)
|
|
4
|
+
|
|
5
|
+
----
|
|
6
|
+
|
|
7
|
+
# RadioButton
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
|parameter | type | required | options | default | description |
|
|
12
|
+
|:--- | :--- | :--- | :--- | :--- | :--- |
|
|
13
|
+
|name | String | yes | | | |
|
|
14
|
+
|buttons | Object | yes | | | Ex. { buttons: [{ id: 'my-id', label: 'my-label', value: 'my-value', checked: true }] } |
|
|
15
|
+
|buttons[0].id | String | yes | | | Ex. { buttons: [{ id: 'my-id' }] } |
|
|
16
|
+
|buttons[0].value | String | yes | | | Ex. { buttons: [{ value: 'my-value' }] } |
|
|
17
|
+
|buttons[0].label | String | no | | | Ex. { buttons: [{ label: 'my-label' }] } |
|
|
18
|
+
|buttons[0].selected | bool | no | true, false | false | Ex. { buttons: [{ selected: true }] } |
|
|
19
|
+
|disabled | bool | no | true, false | false | |
|
|
20
|
+
|error | bool | no | true, false | false | |
|
|
21
|
+
|errorMessage | String | no | | | |
|
|
22
|
+
|required | bool | no | true, false | false | |
|
|
23
|
+
|~validation~ | String | no | | | Not implemented |
|
|
24
|
+
|attributes | Object | no | | | Ex. { target: "_blank", "data-test": "lorem ipsum" } |
|
|
25
|
+
|classNames | String | no | | | Ex. "my-special-class" |
|
|
26
|
+
|forcePx | bool | no | true, false | false | Fixed pixel value is used for typography to prevent scaling based on html font-size |
|
|
27
|
+
|
|
28
|
+
## Minimum requirement example
|
|
29
|
+
|
|
30
|
+
### Nunjucks
|
|
31
|
+
|
|
32
|
+
These are copy paste friendly examples to quickliy get started using a component.
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
{% from '@bonniernews/dn-design-system-web/components/radio-button/radio-button.njk' import RadioButton %}
|
|
36
|
+
|
|
37
|
+
{{ RadioButton({
|
|
38
|
+
name: 'radio_name',
|
|
39
|
+
buttons: [
|
|
40
|
+
{ label: 'radio-label-1', id: 'radio-id-1', value: 'radio-value-1' },
|
|
41
|
+
{ label: 'radio-label-2', id: 'radio-id-2', value: 'radio-value-2', checked: true }
|
|
42
|
+
]
|
|
43
|
+
})}}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### SCSS
|
|
47
|
+
```scss
|
|
48
|
+
@use "@bonniernews/dn-design-system-web/components/radio-button/radio-button";
|
|
49
|
+
```
|
|
@@ -1,49 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
|
12
|
-
|
|
13
|
-
|name |
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
{{ RadioButton({
|
|
38
|
-
name: 'radio_name',
|
|
39
|
-
buttons: [
|
|
40
|
-
{ label: 'radio-label-1', id: 'radio-id-1', value: 'radio-value-1' },
|
|
41
|
-
{ label: 'radio-label-2', id: 'radio-id-2', value: 'radio-value-2', checked: true }
|
|
42
|
-
]
|
|
43
|
-
})}}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### SCSS
|
|
47
|
-
```scss
|
|
48
|
-
@use "@bonniernews/dn-design-system-web/components/radio-button/radio-button";
|
|
49
|
-
```
|
|
1
|
+
RadioButton
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
* GitHub: [BonnierNews/dn-design-system/../web/src/components/radio-button](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/radio-button)
|
|
5
|
+
* Storybook: [Checkbox](https://designsystem.dn.se/?path=/docs/basic-form-radiobutton--docs)
|
|
6
|
+
|
|
7
|
+
The component will not include styling by itself. Make sure to include the right styles for the component. See example below: `@use '@bonniernews/dn-design-system-web/components/radio-button/radio-button.scss`
|
|
8
|
+
|
|
9
|
+
| Name | Description | Default |
|
|
10
|
+
|:--- | :--- | :--- |
|
|
11
|
+
| buttons\* | ButtonProps\[\] | \- |
|
|
12
|
+
| id\* | string | \- |
|
|
13
|
+
| name | string | \- |
|
|
14
|
+
| error | boolean | \- |
|
|
15
|
+
| errorMessage | string | \- |
|
|
16
|
+
| required | boolean | \- |
|
|
17
|
+
| stripLabel | boolean | \- |
|
|
18
|
+
| disabled | boolean | \- |
|
|
19
|
+
| validation | string | \- |
|
|
20
|
+
| classNames | string | \- |
|
|
21
|
+
| forcePx | boolean | \- |
|
|
22
|
+
| attributes | {} | \- |
|
|
23
|
+
|
|
24
|
+
```jsx
|
|
25
|
+
<RadioButton
|
|
26
|
+
buttons={[
|
|
27
|
+
{
|
|
28
|
+
id: 'my_radio_name',
|
|
29
|
+
selected: false,
|
|
30
|
+
value: 'my_radio_value'
|
|
31
|
+
}
|
|
32
|
+
]}
|
|
33
|
+
name="my_radio_name"
|
|
34
|
+
/>
|
|
35
|
+
```
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
- GitHub: [BonnierNews/dn-design-system/../web/src/components/switch](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/switch)
|
|
2
|
+
- Storybook: [Form > Switch](https://designsystem.dn.se/?path=/docs/basic-form-switch--docs)
|
|
3
|
+
- Storybook (Latest): [Form > Switch](https://designsystem-latest.dn.se/?path=/docs/basic-form-switch--docs)
|
|
4
|
+
----
|
|
5
|
+
|
|
6
|
+
# Switch
|
|
7
|
+
|
|
8
|
+
## Parameters
|
|
9
|
+
|
|
10
|
+
|parameter | type | required | options | default | description |
|
|
11
|
+
|:--- | :--- | :--- | :--- | :--- | :--- |
|
|
12
|
+
|name | String | yes | yes | | Also used as id |
|
|
13
|
+
|meta | bool | no | true, false | false | Decides if meta text is shown |
|
|
14
|
+
|metaOn | String | no | | på | |
|
|
15
|
+
|metaOff | String | no | | av | |
|
|
16
|
+
|checked | bool | no | true, false | false | |
|
|
17
|
+
|disabled | bool | no | true, false | false | |
|
|
18
|
+
|attributes | Object | no | | | Ex. { target: "_blank", "data-test": "lorem ipsum" } |
|
|
19
|
+
|classNames | String | no | | | Ex. "my-special-class" |
|
|
20
|
+
|forcePx | bool | no | true, false | false | Fixed pixel value is used for typography to prevent scaling based on html font-size |
|
|
21
|
+
|
|
22
|
+
## Minimum requirement example
|
|
23
|
+
|
|
24
|
+
### Nunjucks
|
|
25
|
+
|
|
26
|
+
These are copy paste friendly examples to quickliy get started using a component.
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
{% from '@bonniernews/dn-design-system-web/components/switch/switch.njk' import Switch %}
|
|
30
|
+
|
|
31
|
+
{{ Switch({
|
|
32
|
+
meta: true,
|
|
33
|
+
metaOn: "On",
|
|
34
|
+
metaOff: "Off",
|
|
35
|
+
name: "my_switch"
|
|
36
|
+
})}}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### SCSS
|
|
40
|
+
```scss
|
|
41
|
+
@use "@bonniernews/dn-design-system-web/components/switch/switch";
|
|
42
|
+
```
|
|
@@ -1,42 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|checked |
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
{% from '@bonniernews/dn-design-system-web/components/switch/switch.njk' import Switch %}
|
|
30
|
-
|
|
31
|
-
{{ Switch({
|
|
32
|
-
meta: true,
|
|
33
|
-
metaOn: "On",
|
|
34
|
-
metaOff: "Off",
|
|
35
|
-
name: "my_switch"
|
|
36
|
-
})}}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### SCSS
|
|
40
|
-
```scss
|
|
41
|
-
@use "@bonniernews/dn-design-system-web/components/switch/switch";
|
|
42
|
-
```
|
|
1
|
+
Switch
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
* GitHub: [BonnierNews/dn-design-system/../web/src/components/switch](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/switch)
|
|
5
|
+
* Storybook: [Checkbox](https://designsystem.dn.se/?path=/docs/basic-form-switch--docs)
|
|
6
|
+
|
|
7
|
+
The component will not include styling by itself. Make sure to include the right styles for the component. See example below: `@use '@bonniernews/dn-design-system-web/components/switch/switch.scss`
|
|
8
|
+
|
|
9
|
+
| Name | Description | Default |
|
|
10
|
+
|:--- | :--- | :--- |
|
|
11
|
+
| name | string | "ds-switch" |
|
|
12
|
+
| showMeta | boolean | false |
|
|
13
|
+
| metaOn | string | "På" |
|
|
14
|
+
| metaOff | string | "Av" |
|
|
15
|
+
| stripLabel | boolean | \- |
|
|
16
|
+
| checked | boolean | \- |
|
|
17
|
+
| required | boolean | \- |
|
|
18
|
+
| disabled | boolean | \- |
|
|
19
|
+
| validation | string | \- |
|
|
20
|
+
| classNames | string | \- |
|
|
21
|
+
| forcePx | boolean | \- |
|
|
22
|
+
| attributes | {} | \- |
|
|
23
|
+
|
|
24
|
+
```jsx
|
|
25
|
+
<Switch
|
|
26
|
+
name="switch1"
|
|
27
|
+
/>
|
|
28
|
+
```
|
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentChildren } from "preact";
|
|
2
|
+
export interface FormFieldProps {
|
|
3
|
+
error?: boolean;
|
|
4
|
+
errorMessage?: string;
|
|
5
|
+
wrapperClasses?: string;
|
|
6
|
+
helpHtml?: string;
|
|
7
|
+
helpText?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
children?: ComponentChildren;
|
|
10
|
+
}
|
|
11
|
+
export declare const FormField: ({ errorMessage, wrapperClasses, helpHtml, helpText, type, children }: FormFieldProps) => import("preact").JSX.Element;
|
|
12
|
+
export default FormField;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { DsIcon } from '@bonniernews/dn-design-system-web/types-lib/ds-icon.d.ts';
|
|
2
|
+
export interface ButtonSharedProps {
|
|
3
|
+
/** Note: only works on button-tag, not on a-tag */
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
classNames?: string;
|
|
6
|
+
/** Ex. { target: "_blank", "data-test": "lorem ipsum" } */
|
|
7
|
+
attributes?: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
/** Fixed pixel value is used for typography to prevent scaling based on html font-size */
|
|
11
|
+
forcePx?: boolean;
|
|
12
|
+
size?: 'small' | 'medium' | 'large' | 'xlarge';
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface AllyProps {
|
|
16
|
+
visuallyHidden?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ButtonBaseProps extends ButtonSharedProps {
|
|
19
|
+
/** Design variant */
|
|
20
|
+
variant?: 'primary' | 'secondary' | 'brand' | 'staticWhite';
|
|
21
|
+
text?: string;
|
|
22
|
+
emphasis?: 'default' | 'elevated' | 'outline' | 'transparent';
|
|
23
|
+
/** Button will be rounded */
|
|
24
|
+
rounded?: boolean;
|
|
25
|
+
/** Button will be full width on both desktop and mobile */
|
|
26
|
+
fullWidth?: boolean;
|
|
27
|
+
/** Button will only full width on mobile */
|
|
28
|
+
mobileFullWidth?: boolean;
|
|
29
|
+
iconPosition?: 'none' | 'left' | 'right';
|
|
30
|
+
/** add, arrow_back, arrow_forward etc | | For all available icons see: https://designsystem.dn.se/?path=/story/foundations-icons--all-icons */
|
|
31
|
+
iconName?: DsIcon;
|
|
32
|
+
type?: 'button' | 'submit';
|
|
33
|
+
/** If href is set the button will be rendered as an a-tag */
|
|
34
|
+
href?: string;
|
|
35
|
+
isIconButton?: boolean;
|
|
36
|
+
a11y?: AllyProps;
|
|
37
|
+
selected?: boolean;
|
|
38
|
+
isToggle?: boolean;
|
|
39
|
+
selectedIconName?: DsIcon;
|
|
40
|
+
selectedText?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface InnerButtonProps {
|
|
43
|
+
text?: string;
|
|
44
|
+
isIconButton?: boolean;
|
|
45
|
+
attributes?: object | any;
|
|
46
|
+
a11y?: AllyProps;
|
|
47
|
+
icon?: any;
|
|
48
|
+
loadingHtml?: any;
|
|
49
|
+
}
|
|
50
|
+
export interface ToggleWrapperProps {
|
|
51
|
+
selected?: boolean;
|
|
52
|
+
classes?: string;
|
|
53
|
+
attributes?: object;
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
loadingHtml?: any;
|
|
56
|
+
onChild?: any;
|
|
57
|
+
offChild?: any;
|
|
58
|
+
}
|
|
59
|
+
export interface ButtonProps extends ButtonSharedProps, Pick<ButtonBaseProps, 'text' | 'variant' | 'emphasis' | 'rounded' | 'fullWidth' | 'mobileFullWidth' | 'iconPosition' | 'iconName' | 'type' | 'href'> {
|
|
60
|
+
text: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ButtonToggleProps extends ButtonSharedProps, Pick<ButtonBaseProps, 'selected' | 'text' | 'selectedText' | 'fullWidth' | 'mobileFullWidth'> {
|
|
63
|
+
selectedText: string;
|
|
64
|
+
variant?: 'primary' | 'secondary' | 'brand';
|
|
65
|
+
}
|
|
66
|
+
export interface IconButtonProps extends ButtonSharedProps, Pick<ButtonBaseProps, 'iconName' | 'emphasis' | 'rounded' | 'href'> {
|
|
67
|
+
a11y?: object;
|
|
68
|
+
variant?: 'primary' | 'secondary' | 'brand';
|
|
69
|
+
}
|
|
70
|
+
export interface IconButtonToggleProps extends ButtonSharedProps, Pick<ButtonBaseProps, 'iconName' | 'emphasis' | 'selectedIconName'> {
|
|
71
|
+
selected?: boolean;
|
|
72
|
+
variant?: 'primary' | 'secondary' | 'brand';
|
|
73
|
+
}
|