@ks-digital/designsystem-angular 0.0.1-alpha.25 → 0.0.1-alpha.28
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/__internals/index.d.ts +54 -0
- package/alert/index.d.ts +17 -0
- package/button/index.d.ts +29 -0
- package/card/index.d.ts +22 -0
- package/details/index.d.ts +26 -0
- package/fesm2022/ks-digital-designsystem-angular-__internals.mjs +50 -0
- package/fesm2022/ks-digital-designsystem-angular-__internals.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-alert.mjs +35 -0
- package/fesm2022/ks-digital-designsystem-angular-alert.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-button.mjs +63 -0
- package/fesm2022/ks-digital-designsystem-angular-button.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-card.mjs +70 -0
- package/fesm2022/ks-digital-designsystem-angular-card.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-details.mjs +100 -0
- package/fesm2022/ks-digital-designsystem-angular-details.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-forms.mjs +408 -0
- package/fesm2022/ks-digital-designsystem-angular-forms.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-paragraph.mjs +24 -0
- package/fesm2022/ks-digital-designsystem-angular-paragraph.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-popover.mjs +165 -0
- package/fesm2022/ks-digital-designsystem-angular-popover.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-search.mjs +181 -0
- package/fesm2022/ks-digital-designsystem-angular-search.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-spinner.mjs +89 -0
- package/fesm2022/ks-digital-designsystem-angular-spinner.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular-validation-message.mjs +25 -0
- package/fesm2022/ks-digital-designsystem-angular-validation-message.mjs.map +1 -0
- package/fesm2022/ks-digital-designsystem-angular.mjs +7 -0
- package/fesm2022/ks-digital-designsystem-angular.mjs.map +1 -0
- package/forms/index.d.ts +100 -0
- package/index.d.ts +2 -0
- package/package.json +59 -20
- package/paragraph/index.d.ts +8 -0
- package/popover/index.d.ts +25 -0
- package/search/index.d.ts +84 -0
- package/spinner/index.d.ts +25 -0
- package/validation-message/index.d.ts +8 -0
- package/.storybook/customTheme.ts +0 -15
- package/.storybook/default-args.ts +0 -18
- package/.storybook/main.ts +0 -27
- package/.storybook/manager.ts +0 -10
- package/.storybook/preview-head.html +0 -16
- package/.storybook/preview.ts +0 -70
- package/.storybook/themes.ts +0 -9
- package/.storybook/tsconfig.json +0 -16
- package/.storybook/vite.config.mts +0 -5
- package/eslint.config.mjs +0 -28
- package/ng-package.json +0 -9
- package/project.json +0 -81
- package/src/components/alert/alert.mdx +0 -46
- package/src/components/alert/alert.spec.ts +0 -33
- package/src/components/alert/alert.stories.ts +0 -138
- package/src/components/alert/alert.ts +0 -46
- package/src/components/alert/index.ts +0 -1
- package/src/components/button/button.mdx +0 -40
- package/src/components/button/button.spec.ts +0 -86
- package/src/components/button/button.stories.ts +0 -123
- package/src/components/button/button.ts +0 -60
- package/src/components/button/index.ts +0 -1
- package/src/components/card/card-block.ts +0 -10
- package/src/components/card/card.mdx +0 -100
- package/src/components/card/card.spec.ts +0 -70
- package/src/components/card/card.stories.ts +0 -101
- package/src/components/card/card.ts +0 -44
- package/src/components/card/index.ts +0 -2
- package/src/components/checkbox/README.md +0 -13
- package/src/components/checkbox/checkbox.mdx +0 -50
- package/src/components/checkbox/checkbox.spec.ts +0 -21
- package/src/components/checkbox/checkbox.stories.ts +0 -182
- package/src/components/checkbox/index.ts +0 -0
- package/src/components/colors.ts +0 -36
- package/src/components/common-inputs.ts +0 -30
- package/src/components/details/controlled-details.ts +0 -63
- package/src/components/details/details-content.ts +0 -7
- package/src/components/details/details-summary.ts +0 -7
- package/src/components/details/details.mdx +0 -89
- package/src/components/details/details.spec.ts +0 -56
- package/src/components/details/details.stories.ts +0 -129
- package/src/components/details/details.ts +0 -69
- package/src/components/details/index.ts +0 -3
- package/src/components/field/field-counter.ts +0 -56
- package/src/components/field/field-description.ts +0 -10
- package/src/components/field/field-error.ts +0 -13
- package/src/components/field/field-observer.ts +0 -121
- package/src/components/field/field-state.ts +0 -21
- package/src/components/field/field.mdx +0 -40
- package/src/components/field/field.spec.ts +0 -131
- package/src/components/field/field.stories.ts +0 -98
- package/src/components/field/field.ts +0 -70
- package/src/components/field/index.ts +0 -3
- package/src/components/fieldset/fieldset-description.ts +0 -8
- package/src/components/fieldset/fieldset-legend.ts +0 -11
- package/src/components/fieldset/fieldset.spec.ts +0 -80
- package/src/components/fieldset/fieldset.ts +0 -11
- package/src/components/fieldset/index.ts +0 -3
- package/src/components/input/index.ts +0 -1
- package/src/components/input/input.mdx +0 -11
- package/src/components/input/input.spec.ts +0 -25
- package/src/components/input/input.stories.ts +0 -72
- package/src/components/input/input.ts +0 -67
- package/src/components/label/index.ts +0 -1
- package/src/components/label/label.ts +0 -17
- package/src/components/paragraph/index.ts +0 -1
- package/src/components/paragraph/paragraph.ts +0 -10
- package/src/components/popover/controlled-popover.ts +0 -62
- package/src/components/popover/index.ts +0 -1
- package/src/components/popover/popover.mdx +0 -81
- package/src/components/popover/popover.spec.ts +0 -143
- package/src/components/popover/popover.stories.ts +0 -63
- package/src/components/popover/popover.ts +0 -186
- package/src/components/radio/radio.mdx +0 -117
- package/src/components/radio/radio.stories.ts +0 -226
- package/src/components/search/index.ts +0 -4
- package/src/components/search/search-button.ts +0 -35
- package/src/components/search/search-clear.ts +0 -57
- package/src/components/search/search-input.ts +0 -18
- package/src/components/search/search.mdx +0 -56
- package/src/components/search/search.spec.ts +0 -48
- package/src/components/search/search.stories.ts +0 -205
- package/src/components/search/search.ts +0 -50
- package/src/components/spinner/index.ts +0 -1
- package/src/components/spinner/spinner.mdx +0 -24
- package/src/components/spinner/spinner.spec.ts +0 -13
- package/src/components/spinner/spinner.stories.ts +0 -54
- package/src/components/spinner/spinner.ts +0 -62
- package/src/components/switch/switch.mdx +0 -82
- package/src/components/switch/switch.stories.ts +0 -94
- package/src/components/textarea/textarea.mdx +0 -14
- package/src/components/textarea/textarea.stories.ts +0 -52
- package/src/components/validation-message/index.ts +0 -1
- package/src/components/validation-message/validation-message.ts +0 -11
- package/src/index.ts +0 -14
- package/src/test-setup.ts +0 -12
- package/src/utils/log-if-devmode.ts +0 -13
- package/src/utils/random-id.ts +0 -3
- package/tsconfig.json +0 -34
- package/tsconfig.lib.json +0 -28
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -30
- package/vite.config.mts +0 -35
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
argsToTemplate,
|
|
3
|
-
moduleMetadata,
|
|
4
|
-
type Meta,
|
|
5
|
-
type StoryObj,
|
|
6
|
-
} from '@storybook/angular'
|
|
7
|
-
import { CommonArgs } from '../../../.storybook/default-args'
|
|
8
|
-
import { Field } from '../field/field'
|
|
9
|
-
import { FieldDescription } from '../field/field-description'
|
|
10
|
-
import { Fieldset } from '../fieldset/fieldset'
|
|
11
|
-
import { FieldsetDescription } from '../fieldset/fieldset-description'
|
|
12
|
-
import { FieldsetLegend } from '../fieldset/fieldset-legend'
|
|
13
|
-
import { Input } from '../input/input'
|
|
14
|
-
import { Label } from '../label/label'
|
|
15
|
-
import { ValidationMessage } from '../validation-message'
|
|
16
|
-
|
|
17
|
-
type RadioArgs = CommonArgs & {
|
|
18
|
-
readonly: boolean
|
|
19
|
-
disabled: boolean
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const meta: Meta<Input> = {
|
|
23
|
-
component: Input,
|
|
24
|
-
title: 'Komponenter/Radio',
|
|
25
|
-
decorators: [
|
|
26
|
-
moduleMetadata({
|
|
27
|
-
imports: [
|
|
28
|
-
Label,
|
|
29
|
-
Field,
|
|
30
|
-
Input,
|
|
31
|
-
FieldDescription,
|
|
32
|
-
Fieldset,
|
|
33
|
-
FieldsetLegend,
|
|
34
|
-
FieldsetDescription,
|
|
35
|
-
ValidationMessage,
|
|
36
|
-
],
|
|
37
|
-
}),
|
|
38
|
-
],
|
|
39
|
-
}
|
|
40
|
-
export default meta
|
|
41
|
-
type Story = StoryObj<RadioArgs>
|
|
42
|
-
|
|
43
|
-
export const Preview: Story = {
|
|
44
|
-
args: {
|
|
45
|
-
readonly: false,
|
|
46
|
-
disabled: false,
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
render: (args) => ({
|
|
50
|
-
props: args,
|
|
51
|
-
template: `
|
|
52
|
-
<ksd-field>
|
|
53
|
-
<ksd-label>Label</ksd-label>
|
|
54
|
-
<input type="radio" ksd-input ${argsToTemplate(args)} />
|
|
55
|
-
<p ksd-field-description>Description</p>
|
|
56
|
-
</ksd-field>
|
|
57
|
-
`,
|
|
58
|
-
}),
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const AriaLabel: Story = {
|
|
62
|
-
args: {
|
|
63
|
-
...Preview.args,
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
render: (args) => ({
|
|
67
|
-
props: args,
|
|
68
|
-
template: `
|
|
69
|
-
<input ksd-input type="radio" ${argsToTemplate(args)} aria-label="Radio" />
|
|
70
|
-
`,
|
|
71
|
-
}),
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const Group: Story = {
|
|
75
|
-
args: {
|
|
76
|
-
...Preview.args,
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
render: (args) => ({
|
|
80
|
-
props: args,
|
|
81
|
-
template: `
|
|
82
|
-
<fieldset ksd-fieldset>
|
|
83
|
-
<legend ksd-fieldset-legend>Hvilken iskremsmak er best ? </legend>
|
|
84
|
-
<p ksd-fieldset-description>Velg din favorittsmak blant alternativene.</p>
|
|
85
|
-
<ksd-field>
|
|
86
|
-
<ksd-label>Vanilje</ksd-label>
|
|
87
|
-
<input type="radio" name="icecream" ksd-input ${argsToTemplate(args)} />
|
|
88
|
-
</ksd-field>
|
|
89
|
-
<ksd-field>
|
|
90
|
-
<ksd-label>Jordbær</ksd-label>
|
|
91
|
-
<input type="radio" name="icecream" ksd-input ${argsToTemplate(args)} />
|
|
92
|
-
</ksd-field>
|
|
93
|
-
<ksd-field>
|
|
94
|
-
<ksd-label>Sjokolade</ksd-label>
|
|
95
|
-
<input type="radio" name="icecream" ksd-input ${argsToTemplate(args)} />
|
|
96
|
-
</ksd-field>
|
|
97
|
-
<ksd-field>
|
|
98
|
-
<ksd-label>Jeg spiser ikke iskrem</ksd-label>
|
|
99
|
-
<input type="radio" name="icecream" ksd-input ${argsToTemplate(args)} />
|
|
100
|
-
</ksd-field>
|
|
101
|
-
</fieldset>
|
|
102
|
-
`,
|
|
103
|
-
}),
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const WithError: Story = {
|
|
107
|
-
args: {
|
|
108
|
-
...Preview.args,
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
render: (args) => ({
|
|
112
|
-
props: args,
|
|
113
|
-
template: `
|
|
114
|
-
<fieldset ksd-fieldset>
|
|
115
|
-
<legend ksd-fieldset-legend>Hvilken bydel bor du i?</legend>
|
|
116
|
-
<p ksd-fieldset-description>Bergen er delt inn i åtte bydeler</p>
|
|
117
|
-
<ksd-field>
|
|
118
|
-
<ksd-label>Arna</ksd-label>
|
|
119
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
120
|
-
</ksd-field>
|
|
121
|
-
<ksd-field>
|
|
122
|
-
<ksd-label>Bergenhus</ksd-label>
|
|
123
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
124
|
-
</ksd-field>
|
|
125
|
-
<ksd-field>
|
|
126
|
-
<ksd-label>Fana</ksd-label>
|
|
127
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
128
|
-
</ksd-field>
|
|
129
|
-
<ksd-field>
|
|
130
|
-
<ksd-label>Fyllingsdalen</ksd-label>
|
|
131
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
132
|
-
</ksd-field>
|
|
133
|
-
<ksd-field>
|
|
134
|
-
<ksd-label>Laksevåg</ksd-label>
|
|
135
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
136
|
-
</ksd-field>
|
|
137
|
-
<ksd-field>
|
|
138
|
-
<ksd-label>Ytrebygda</ksd-label>
|
|
139
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
140
|
-
</ksd-field>
|
|
141
|
-
<ksd-field>
|
|
142
|
-
<ksd-label>Årstad</ksd-label>
|
|
143
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
144
|
-
</ksd-field>
|
|
145
|
-
<ksd-field>
|
|
146
|
-
<ksd-label>Åsane</ksd-label>
|
|
147
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
148
|
-
</ksd-field>
|
|
149
|
-
<p ksd-validation-message>Du må velge en bydel før du kan fortsette.</p>
|
|
150
|
-
`,
|
|
151
|
-
}),
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export const ReadOnly: Story = {
|
|
155
|
-
args: {
|
|
156
|
-
...Preview.args,
|
|
157
|
-
readonly: true,
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
render: (args) => ({
|
|
161
|
-
props: args,
|
|
162
|
-
template: `
|
|
163
|
-
<fieldset ksd-fieldset>
|
|
164
|
-
<legend ksd-fieldset-legend>Hvilken bydel bor du i?</legend>
|
|
165
|
-
<p ksd-fieldset-description>Bergen er delt inn i åtte bydeler</p>
|
|
166
|
-
<ksd-field>
|
|
167
|
-
<ksd-label>Arna</ksd-label>
|
|
168
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
169
|
-
</ksd-field>
|
|
170
|
-
<ksd-field>
|
|
171
|
-
<ksd-label>Bergenhus</ksd-label>
|
|
172
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
173
|
-
</ksd-field>
|
|
174
|
-
<ksd-field>
|
|
175
|
-
<ksd-label>Fana</ksd-label>
|
|
176
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
177
|
-
</ksd-field>
|
|
178
|
-
<ksd-field>
|
|
179
|
-
<ksd-label>Fyllingsdalen</ksd-label>
|
|
180
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
181
|
-
</ksd-field>
|
|
182
|
-
<ksd-field>
|
|
183
|
-
<ksd-label>Laksevåg</ksd-label>
|
|
184
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
185
|
-
</ksd-field>
|
|
186
|
-
<ksd-field>
|
|
187
|
-
<ksd-label>Ytrebygda</ksd-label>
|
|
188
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
189
|
-
</ksd-field>
|
|
190
|
-
<ksd-field>
|
|
191
|
-
<ksd-label>Årstad</ksd-label>
|
|
192
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
193
|
-
</ksd-field>
|
|
194
|
-
<ksd-field>
|
|
195
|
-
<ksd-label>Åsane</ksd-label>
|
|
196
|
-
<input type="radio" name="city" ksd-input ${argsToTemplate(args)} />
|
|
197
|
-
</ksd-field>
|
|
198
|
-
`,
|
|
199
|
-
}),
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export const Inline: Story = {
|
|
203
|
-
args: {
|
|
204
|
-
...Preview.args,
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
render: (args) => ({
|
|
208
|
-
props: args,
|
|
209
|
-
template: `
|
|
210
|
-
<fieldset ksd-fieldset>
|
|
211
|
-
<legend ksd-fieldset-legend>Kontaktes på e-post?</legend>
|
|
212
|
-
<p ksd-fieldset-description>Bekreft om du ønsker å bli kontaktet per e-post.</p>
|
|
213
|
-
<div style="display: flex; flex-wrap: wrap; gap: var(--ds-size-6)">
|
|
214
|
-
<ksd-field>
|
|
215
|
-
<ksd-label>Ja</ksd-label>
|
|
216
|
-
<input type="radio" name="my-inline" ksd-input ${argsToTemplate(args)} />
|
|
217
|
-
</ksd-field>
|
|
218
|
-
<ksd-field>
|
|
219
|
-
<ksd-label>Nei</ksd-label>
|
|
220
|
-
<input type="radio" name="my-inline" ksd-input ${argsToTemplate(args)} />
|
|
221
|
-
</ksd-field>
|
|
222
|
-
</div>
|
|
223
|
-
</fieldset>
|
|
224
|
-
`,
|
|
225
|
-
}),
|
|
226
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Directive, input } from '@angular/core'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Search button
|
|
5
|
-
*
|
|
6
|
-
* Used within Search to provide a submit button.
|
|
7
|
-
*
|
|
8
|
-
* @param {('primary' | 'secondary')} [variant] - Specify which button variant to use
|
|
9
|
-
* @param {string} [aria-label] - Aria label for the button
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
@Directive({
|
|
13
|
-
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
14
|
-
selector: 'button[ksd-search-button]',
|
|
15
|
-
standalone: true,
|
|
16
|
-
host: {
|
|
17
|
-
class: 'ds-button',
|
|
18
|
-
type: 'submit',
|
|
19
|
-
'[attr.aria-label]': 'this.ariaLabel()',
|
|
20
|
-
'[attr.data-variant]': 'this.variant()',
|
|
21
|
-
},
|
|
22
|
-
})
|
|
23
|
-
export class SearchButton {
|
|
24
|
-
/**
|
|
25
|
-
* Specify which button variant to use
|
|
26
|
-
*
|
|
27
|
-
* @default 'primary'
|
|
28
|
-
*/
|
|
29
|
-
readonly variant = input<'primary' | 'secondary'>('primary')
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Aria label for the button
|
|
33
|
-
*/
|
|
34
|
-
readonly ariaLabel = input('', { alias: 'aria-label' })
|
|
35
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Directive, input, output } from '@angular/core'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Search clear button
|
|
5
|
-
*
|
|
6
|
-
* Used within Search to provide a clear button.
|
|
7
|
-
*
|
|
8
|
-
* @param {string} [aria-label] - Aria label for the button.
|
|
9
|
-
*
|
|
10
|
-
* @event clearInput - Emitted when the clear button is clicked.
|
|
11
|
-
* Use this to notify controlled forms that the input should be cleared.
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
@Directive({
|
|
15
|
-
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
16
|
-
selector: 'button[ksd-search-clear]',
|
|
17
|
-
standalone: true,
|
|
18
|
-
host: {
|
|
19
|
-
class: 'ds-button',
|
|
20
|
-
type: 'reset',
|
|
21
|
-
'[attr.data-variant]': "'tertiary'",
|
|
22
|
-
'[attr.aria-label]': 'this.ariaLabel()',
|
|
23
|
-
'(click)': 'handleClear($event)',
|
|
24
|
-
},
|
|
25
|
-
})
|
|
26
|
-
export class SearchClear {
|
|
27
|
-
/**
|
|
28
|
-
* Aria label for the button
|
|
29
|
-
* @default 'Tøm'
|
|
30
|
-
*/
|
|
31
|
-
readonly ariaLabel = input('Tøm', { alias: 'aria-label' })
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Output to notify controlled forms that input should be cleared
|
|
35
|
-
*/
|
|
36
|
-
clearInput = output<void>()
|
|
37
|
-
|
|
38
|
-
handleClear(e: Event): void {
|
|
39
|
-
const target = e.target as HTMLButtonElement
|
|
40
|
-
let inputElement: HTMLElement | null | undefined = null
|
|
41
|
-
|
|
42
|
-
if (target instanceof HTMLElement) {
|
|
43
|
-
inputElement = target.closest('.ds-search')?.querySelector('input')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!inputElement) throw new Error('Input is missing')
|
|
47
|
-
|
|
48
|
-
if (!(inputElement instanceof HTMLInputElement)) {
|
|
49
|
-
throw new Error('Input is not an input element')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
e.preventDefault()
|
|
53
|
-
inputElement.value = ''
|
|
54
|
-
this.clearInput.emit()
|
|
55
|
-
inputElement.focus()
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Directive } from '@angular/core'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Search input
|
|
5
|
-
*
|
|
6
|
-
* Used within Search to provide a search input.
|
|
7
|
-
*/
|
|
8
|
-
@Directive({
|
|
9
|
-
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
10
|
-
selector: 'input[ksd-search-input]',
|
|
11
|
-
standalone: true,
|
|
12
|
-
host: {
|
|
13
|
-
class: 'ds-input',
|
|
14
|
-
type: 'search',
|
|
15
|
-
placeholder: '', // Need empty placeholder to enable show/hide for clear button
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
export class SearchInput {}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Meta,
|
|
3
|
-
Primary,
|
|
4
|
-
Controls,
|
|
5
|
-
Story,
|
|
6
|
-
Canvas,
|
|
7
|
-
} from '@storybook/addon-docs/blocks'
|
|
8
|
-
|
|
9
|
-
import * as SearchStories from './search.stories'
|
|
10
|
-
|
|
11
|
-
<Meta of={SearchStories} />
|
|
12
|
-
|
|
13
|
-
# Search
|
|
14
|
-
|
|
15
|
-
Search lar brukere raskt finne relevant innhold på et nettsted i en applikasjon. Komponenten består av et søkefelt, med eller uten en søkeknapp
|
|
16
|
-
|
|
17
|
-
<Primary />
|
|
18
|
-
<Controls />
|
|
19
|
-
|
|
20
|
-
## Bruk
|
|
21
|
-
|
|
22
|
-
```tsx
|
|
23
|
-
import {
|
|
24
|
-
Search,
|
|
25
|
-
SearchInput,
|
|
26
|
-
SearchClear,
|
|
27
|
-
SearchButton,
|
|
28
|
-
} from '@ks-digital/designsystem-angular'
|
|
29
|
-
;<ksd-search>
|
|
30
|
-
<input ksd-search-input />
|
|
31
|
-
<button ksd-search-clear></button>
|
|
32
|
-
<button ksd-search-button></button>
|
|
33
|
-
</ksd-search>
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Kontrollert
|
|
37
|
-
|
|
38
|
-
<Canvas of={SearchStories.Controlled} />
|
|
39
|
-
|
|
40
|
-
## Variants
|
|
41
|
-
|
|
42
|
-
Du kan endre variant på Button for å tilpasse visningen. Alternativt kan du fjerne knappen for å bruke et søkefelt med ikon. Eksemplene nedenfor viser varianter som inkluderer ikon, primær- og sekundærknapp.
|
|
43
|
-
|
|
44
|
-
<Canvas of={SearchStories.Variants} />
|
|
45
|
-
|
|
46
|
-
## Med Label
|
|
47
|
-
|
|
48
|
-
Dersom du vil ha label på søkefeltet, må du legge til en Label komponent som du kobler sammen med SearchInput. I eksempelet har vi brukt Field for å få oppkobling mellom Label og SearchInput.
|
|
49
|
-
|
|
50
|
-
<Canvas of={SearchStories.WithLabel} />
|
|
51
|
-
|
|
52
|
-
## Skjema
|
|
53
|
-
|
|
54
|
-
Søkeknappen har typen "submit" og vil dermed automatisk sende inn skjema.
|
|
55
|
-
|
|
56
|
-
<Canvas of={SearchStories.Form} />
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/angular'
|
|
2
|
-
import userEvent from '@testing-library/user-event'
|
|
3
|
-
import { Input } from '../input'
|
|
4
|
-
import { Search } from './search'
|
|
5
|
-
import { SearchButton } from './search-button'
|
|
6
|
-
import { SearchClear } from './search-clear'
|
|
7
|
-
import { SearchInput } from './search-input'
|
|
8
|
-
|
|
9
|
-
test('should render minimal search component', async () => {
|
|
10
|
-
await render(
|
|
11
|
-
`
|
|
12
|
-
<ksd-search>
|
|
13
|
-
<input ksd-search-input role="searchbox" />
|
|
14
|
-
</ksd-search>
|
|
15
|
-
`,
|
|
16
|
-
{ imports: [SearchInput, Search, Input] },
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
const searchElement = screen.getByRole('searchbox').parentElement
|
|
20
|
-
expect(searchElement).toBeInTheDocument()
|
|
21
|
-
expect(searchElement).toHaveClass('ds-search')
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('should clear the input when the clear button is clicked', async () => {
|
|
25
|
-
await render(
|
|
26
|
-
`
|
|
27
|
-
<ksd-search>
|
|
28
|
-
<input ksd-search-input role="searchbox" />
|
|
29
|
-
<button ksd-search-clear role="button"></button>
|
|
30
|
-
<button ksd-search-button></button>
|
|
31
|
-
</ksd-search>
|
|
32
|
-
`,
|
|
33
|
-
{
|
|
34
|
-
imports: [SearchInput, SearchClear, SearchButton, Search],
|
|
35
|
-
},
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
const searchInput = screen.getByRole('searchbox') as HTMLInputElement
|
|
39
|
-
const clearButton = screen.getByRole('button', {
|
|
40
|
-
name: /tøm/i,
|
|
41
|
-
}) as HTMLButtonElement
|
|
42
|
-
|
|
43
|
-
await userEvent.type(searchInput, 'test')
|
|
44
|
-
expect(searchInput.value).toBe('test')
|
|
45
|
-
|
|
46
|
-
await userEvent.click(clearButton)
|
|
47
|
-
expect(searchInput.value).toBe('')
|
|
48
|
-
})
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { moduleMetadata, type Meta } from '@storybook/angular'
|
|
2
|
-
import { CommonArgs, commonArgTypes } from '../../../.storybook/default-args'
|
|
3
|
-
import { Button } from '../button'
|
|
4
|
-
import { Field } from '../field/field'
|
|
5
|
-
import { Input } from '../input'
|
|
6
|
-
import { Label } from '../label/label'
|
|
7
|
-
import { Search } from './search'
|
|
8
|
-
import { SearchButton } from './search-button'
|
|
9
|
-
import { SearchClear } from './search-clear'
|
|
10
|
-
import { SearchInput } from './search-input'
|
|
11
|
-
|
|
12
|
-
type SearchArgs = CommonArgs & {
|
|
13
|
-
variant?: 'primary' | 'secondary'
|
|
14
|
-
buttonLabel?: string
|
|
15
|
-
clearButtonLabel?: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const meta: Meta<SearchArgs> = {
|
|
19
|
-
component: Search,
|
|
20
|
-
title: 'Komponenter/Search',
|
|
21
|
-
argTypes: {
|
|
22
|
-
...commonArgTypes,
|
|
23
|
-
variant: {
|
|
24
|
-
options: ['primary', 'secondary'],
|
|
25
|
-
control: { type: 'radio' },
|
|
26
|
-
description: 'Velg variant for søkeknappen',
|
|
27
|
-
},
|
|
28
|
-
buttonLabel: {
|
|
29
|
-
control: { type: 'text' },
|
|
30
|
-
description: 'Label for søkeknappen',
|
|
31
|
-
},
|
|
32
|
-
clearButtonLabel: {
|
|
33
|
-
control: { type: 'text' },
|
|
34
|
-
description: 'Label for tøm-knappen',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
decorators: [
|
|
38
|
-
moduleMetadata({
|
|
39
|
-
imports: [
|
|
40
|
-
Search,
|
|
41
|
-
SearchClear,
|
|
42
|
-
SearchButton,
|
|
43
|
-
SearchInput,
|
|
44
|
-
Button,
|
|
45
|
-
Input,
|
|
46
|
-
Field,
|
|
47
|
-
Label,
|
|
48
|
-
],
|
|
49
|
-
}),
|
|
50
|
-
],
|
|
51
|
-
}
|
|
52
|
-
export default meta
|
|
53
|
-
type Story = Meta<Search>
|
|
54
|
-
|
|
55
|
-
export const Preview: Story = {
|
|
56
|
-
args: {
|
|
57
|
-
variant: 'primary',
|
|
58
|
-
buttonLabel: 'Søk',
|
|
59
|
-
clearButtonLabel: 'Tøm',
|
|
60
|
-
'data-size': '',
|
|
61
|
-
'data-color': '',
|
|
62
|
-
},
|
|
63
|
-
render: (args) => ({
|
|
64
|
-
props: {
|
|
65
|
-
...args,
|
|
66
|
-
dataSize: (args as SearchArgs)['data-size'],
|
|
67
|
-
dataColor: (args as SearchArgs)['data-color'],
|
|
68
|
-
},
|
|
69
|
-
template: `
|
|
70
|
-
<ksd-search role="search" [attr.data-size]="dataSize" [attr.data-color]="dataColor">
|
|
71
|
-
<input ksd-search-input role="searchbox" aria-label="Søkefelt" />
|
|
72
|
-
<button ksd-search-clear [aria-label]="clearButtonLabel"></button>
|
|
73
|
-
<button ksd-search-button [variant]="variant" [aria-label]="buttonLabel"></button>
|
|
74
|
-
</ksd-search>
|
|
75
|
-
`,
|
|
76
|
-
}),
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const Controlled: Story = {
|
|
80
|
-
render: () => {
|
|
81
|
-
const state = {
|
|
82
|
-
value: '',
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
props: {
|
|
86
|
-
state,
|
|
87
|
-
|
|
88
|
-
setInput: (value: string) => {
|
|
89
|
-
state.value = value
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
setValue: (event: KeyboardEvent) => {
|
|
93
|
-
const input = event.target as HTMLInputElement
|
|
94
|
-
state.value = input.value
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
clearValue: () => {
|
|
98
|
-
state.value = ''
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
template: `
|
|
102
|
-
<ksd-search>
|
|
103
|
-
<input ksd-search-input role="searchbox" [value]="state.value" (keyup)="setValue($event)"/>
|
|
104
|
-
<button ksd-search-clear (clearInput)="clearValue()" ></button>
|
|
105
|
-
<button ksd-search-button></button>
|
|
106
|
-
</ksd-search>
|
|
107
|
-
|
|
108
|
-
<div>
|
|
109
|
-
<span>Current search value: "{{ state.value }}"</span>
|
|
110
|
-
|
|
111
|
-
<button ksd-button (click)="setInput('Calzone')">
|
|
112
|
-
Set input value to "Calzone"
|
|
113
|
-
</button>
|
|
114
|
-
|
|
115
|
-
<p>The clear button has an output <em>(clearInput)</em> that is emitted when clicked.</p>
|
|
116
|
-
</div>
|
|
117
|
-
`,
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export const Variants: Story = {
|
|
123
|
-
args: {},
|
|
124
|
-
render: (args) => ({
|
|
125
|
-
props: args,
|
|
126
|
-
template: `
|
|
127
|
-
<div>
|
|
128
|
-
<p>Primary variant (default)</p>
|
|
129
|
-
<ksd-search>
|
|
130
|
-
<input ksd-search-input role="searchbox" />
|
|
131
|
-
<button ksd-search-clear></button>
|
|
132
|
-
<button ksd-search-button></button>
|
|
133
|
-
</ksd-search>
|
|
134
|
-
</div>
|
|
135
|
-
|
|
136
|
-
<div>
|
|
137
|
-
<p>Secondary variant</p>
|
|
138
|
-
<ksd-search>
|
|
139
|
-
<input ksd-search-input role="searchbox" />
|
|
140
|
-
<button ksd-search-clear></button>
|
|
141
|
-
<button ksd-search-button variant="secondary"></button>
|
|
142
|
-
</ksd-search>
|
|
143
|
-
</div>
|
|
144
|
-
|
|
145
|
-
<div>
|
|
146
|
-
<p>Search with icon</p>
|
|
147
|
-
<ksd-search>
|
|
148
|
-
<input ksd-search-input role="searchbox" />
|
|
149
|
-
<button ksd-search-clear></button>
|
|
150
|
-
</ksd-search>
|
|
151
|
-
</div>
|
|
152
|
-
`,
|
|
153
|
-
}),
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export const WithLabel: Story = {
|
|
157
|
-
args: {},
|
|
158
|
-
render: (args) => ({
|
|
159
|
-
props: args,
|
|
160
|
-
template: `
|
|
161
|
-
<ksd-field>
|
|
162
|
-
<ksd-label>Søk etter hunder:</ksd-label>
|
|
163
|
-
<ksd-search>
|
|
164
|
-
<input ksd-search-input role="searchbox" name="dog-search" />
|
|
165
|
-
<button ksd-search-clear></button>
|
|
166
|
-
<button ksd-search-button></button>
|
|
167
|
-
</ksd-search>
|
|
168
|
-
</ksd-field>
|
|
169
|
-
`,
|
|
170
|
-
}),
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export const Form: Story = {
|
|
174
|
-
render: () => {
|
|
175
|
-
const state = { value: '' }
|
|
176
|
-
return {
|
|
177
|
-
props: {
|
|
178
|
-
state,
|
|
179
|
-
onSubmit: (event: Event) => {
|
|
180
|
-
event.preventDefault()
|
|
181
|
-
const form = event.target as HTMLFormElement
|
|
182
|
-
const formData = new FormData(form)
|
|
183
|
-
state.value = formData.get('search') as string
|
|
184
|
-
},
|
|
185
|
-
onClear: () => {
|
|
186
|
-
state.value = ''
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
template: `
|
|
190
|
-
<form role="search" (submit)="onSubmit($event)">
|
|
191
|
-
<ksd-search>
|
|
192
|
-
<input ksd-search-input role="searchbox" name="search" />
|
|
193
|
-
<button ksd-search-clear (clearInput)="onClear()"></button>
|
|
194
|
-
<button ksd-search-button></button>
|
|
195
|
-
</ksd-search>
|
|
196
|
-
</form>
|
|
197
|
-
|
|
198
|
-
<p>Submitted value: "{{ state.value }}"</p>
|
|
199
|
-
`,
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
// play: async ({ canvas }) => {
|
|
203
|
-
// await expect(canvas.getByRole('search')).toBeTruthy()
|
|
204
|
-
// },
|
|
205
|
-
}
|