@oslokommune/punkt-elements 12.17.2 → 12.18.1

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 (128) hide show
  1. package/dist/alert-BbVWu2lm.cjs +27 -0
  2. package/dist/alert-Dh6A96vo.js +159 -0
  3. package/dist/{index-D2jSRMrn.js → calendar-BUqcNvfI.js} +41 -29
  4. package/dist/calendar-QSulz7im.cjs +108 -0
  5. package/dist/card-B0GPdG5M.cjs +23 -0
  6. package/dist/card-kWt0BA2a.js +170 -0
  7. package/dist/{class-map-a5HUzP83.cjs → class-map-Boa7BqCc.cjs} +2 -2
  8. package/dist/{class-map-CBvUV2N3.js → class-map-hz16xq5a.js} +9 -10
  9. package/dist/datepicker-BHepKxof.cjs +154 -0
  10. package/dist/datepicker-iNCYioZ9.js +659 -0
  11. package/dist/helptext--4FLdAWi.js +194 -0
  12. package/dist/helptext-iZEgxz2U.cjs +23 -0
  13. package/dist/icon-CdMQ6zBT.cjs +250 -0
  14. package/dist/{index-CFDwiDTU.js → icon-wUXeHiBk.js} +7371 -7559
  15. package/dist/if-defined-DEDlGbAc.cjs +5 -0
  16. package/dist/if-defined-ZFE4ti2t.js +10 -0
  17. package/dist/index.d.ts +96 -51
  18. package/dist/input-element-D1Vls6A5.js +184 -0
  19. package/dist/input-element-DPKoFVwJ.cjs +1 -0
  20. package/dist/{input-wrapper-6vTrKtsW.js → input-wrapper-BTQk3W8T.js} +10 -10
  21. package/dist/input-wrapper-D-PNRJB_.cjs +46 -0
  22. package/dist/link-BpqavGSD.cjs +8 -0
  23. package/dist/link-Bx9nVgZi.js +108 -0
  24. package/dist/{linkcard-BlWQ8jOv.js → linkcard-CUrbzjLK.js} +16 -17
  25. package/dist/linkcard-DSu3A4Yx.cjs +13 -0
  26. package/dist/messagebox-C1aWoQbu.cjs +12 -0
  27. package/dist/messagebox-LpiVQIoM.js +107 -0
  28. package/dist/{modal-DYTVJjYh.cjs → modal-Avai5eVz.cjs} +2 -2
  29. package/dist/{modal-3OZTPqee.js → modal-Co1YFmHi.js} +8 -8
  30. package/dist/pkt-alert.cjs +1 -27
  31. package/dist/pkt-alert.js +4 -157
  32. package/dist/pkt-calendar.cjs +1 -1
  33. package/dist/pkt-calendar.js +4 -7
  34. package/dist/pkt-card.cjs +1 -23
  35. package/dist/pkt-card.js +4 -168
  36. package/dist/pkt-datepicker.cjs +1 -154
  37. package/dist/pkt-datepicker.js +4 -657
  38. package/dist/pkt-helptext.cjs +1 -1
  39. package/dist/pkt-helptext.js +1 -1
  40. package/dist/pkt-icon.cjs +1 -1
  41. package/dist/pkt-icon.js +4 -4
  42. package/dist/pkt-index.cjs +29 -1
  43. package/dist/pkt-index.js +127 -30
  44. package/dist/pkt-input-wrapper.cjs +1 -1
  45. package/dist/pkt-input-wrapper.js +1 -1
  46. package/dist/pkt-link.cjs +1 -8
  47. package/dist/pkt-link.js +4 -107
  48. package/dist/pkt-linkcard.cjs +1 -1
  49. package/dist/pkt-linkcard.js +1 -1
  50. package/dist/pkt-messagebox.cjs +1 -12
  51. package/dist/pkt-messagebox.js +4 -105
  52. package/dist/pkt-modal.cjs +1 -1
  53. package/dist/pkt-modal.js +1 -1
  54. package/dist/pkt-progressbar.cjs +1 -0
  55. package/dist/pkt-progressbar.js +6 -0
  56. package/dist/pkt-slot-controller-Ckk_yV0j.cjs +1 -0
  57. package/dist/pkt-slot-controller-RJvOnbF4.js +61 -0
  58. package/dist/pkt-tag.cjs +1 -17
  59. package/dist/pkt-tag.js +4 -148
  60. package/dist/pkt-textarea.cjs +1 -1
  61. package/dist/pkt-textarea.js +1 -1
  62. package/dist/pkt-textinput.cjs +1 -1
  63. package/dist/pkt-textinput.js +1 -1
  64. package/dist/progressbar-BS_oawSB.js +150 -0
  65. package/dist/progressbar-CuXkbAhJ.cjs +32 -0
  66. package/dist/ref-DCOsLZQg.cjs +13 -0
  67. package/dist/ref-DuFGTLVX.js +142 -0
  68. package/dist/state-BfyXV7EL.js +12 -0
  69. package/dist/state-SKYD8kRO.cjs +5 -0
  70. package/dist/stringutils-CkVRq4jP.cjs +1 -0
  71. package/dist/stringutils-DJjRa8dG.js +7 -0
  72. package/dist/tag-CGy2mSLE.cjs +17 -0
  73. package/dist/tag-DGFgUF3l.js +150 -0
  74. package/dist/{textarea-BTpJjEhO.js → textarea-BAGWR1Hi.js} +29 -29
  75. package/dist/textarea-BiUrhAlk.cjs +48 -0
  76. package/dist/{textinput-BIhQEr8z.cjs → textinput-CHOR5PPp.cjs} +2 -2
  77. package/dist/{textinput-CVo5wG14.js → textinput-pJ3N8m6g.js} +23 -23
  78. package/package.json +2 -2
  79. package/src/components/alert/alert.ts +115 -0
  80. package/src/components/alert/index.ts +4 -113
  81. package/src/components/calendar/calendar.ts +711 -0
  82. package/src/components/calendar/index.ts +3 -711
  83. package/src/components/card/card.ts +78 -0
  84. package/src/components/card/index.ts +4 -77
  85. package/src/components/datepicker/datepicker.ts +619 -0
  86. package/src/components/datepicker/index.ts +3 -618
  87. package/src/components/helptext/helptext.ts +2 -2
  88. package/src/components/icon/icon.ts +99 -0
  89. package/src/components/icon/index.ts +3 -98
  90. package/src/components/index.ts +29 -15
  91. package/src/components/input-wrapper/input-wrapper.ts +2 -2
  92. package/src/components/link/index.ts +3 -56
  93. package/src/components/link/link.ts +57 -0
  94. package/src/components/linkcard/index.ts +1 -1
  95. package/src/components/linkcard/linkcard.ts +5 -6
  96. package/src/components/messagebox/index.ts +4 -69
  97. package/src/components/messagebox/messagebox.ts +69 -0
  98. package/src/components/modal/index.ts +0 -1
  99. package/src/components/modal/modal.ts +5 -7
  100. package/src/components/progressbar/index.ts +12 -0
  101. package/src/components/progressbar/progressbar.ts +144 -0
  102. package/src/components/tag/index.ts +4 -109
  103. package/src/components/tag/tag.ts +118 -0
  104. package/src/components/textarea/textarea.ts +5 -4
  105. package/src/components/textinput/textinput.ts +3 -3
  106. package/dist/converters-DNCwIFwr.js +0 -17
  107. package/dist/converters-DhM11VlY.cjs +0 -1
  108. package/dist/custom-element-B-TlBwRu.cjs +0 -9
  109. package/dist/custom-element-CWfU4dcr.js +0 -38
  110. package/dist/element.d.ts +0 -8
  111. package/dist/helptext-DBolvFI4.js +0 -72
  112. package/dist/helptext-_fMLOOCL.cjs +0 -23
  113. package/dist/index-CR7t1zY9.cjs +0 -238
  114. package/dist/index-CmTjXoAb.cjs +0 -9
  115. package/dist/index-RwtTBIhT.js +0 -88
  116. package/dist/index-tvpcg-ad.cjs +0 -108
  117. package/dist/input-wrapper-DX41tnbj.cjs +0 -46
  118. package/dist/linkcard-Det6CJ5D.cjs +0 -13
  119. package/dist/pkt-component-template.cjs +0 -29
  120. package/dist/pkt-component-template.js +0 -99
  121. package/dist/pkt-element.cjs +0 -1
  122. package/dist/pkt-element.js +0 -5
  123. package/dist/ref-C2yPtMJA.cjs +0 -13
  124. package/dist/ref-CaiKp3S2.js +0 -202
  125. package/dist/textarea-B45ZZYpx.cjs +0 -48
  126. package/src/components/component-template/index.ts +0 -129
  127. package/src/components/element/index.ts +0 -353
  128. /package/dist/{component-template.d.ts → progressbar.d.ts} +0 -0
@@ -1,353 +0,0 @@
1
- import { LitElement, PropertyValues } from 'lit'
2
- import { property, state } from 'lit/decorators.js'
3
- import { uuidish } from '@/utils/stringutils'
4
- import { renderReactNode } from '@/helpers/renderers'
5
- import strings from '../../translations/no.json'
6
- import inputwrapperspecs from 'componentSpecs/input-wrapper.json'
7
- import 'element-internals-polyfill'
8
-
9
- /**
10
- * Base class for all Punkt elements
11
- * @extends LitElement
12
- */
13
- export class PktElement extends LitElement {
14
- [key: string]: any
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- @property({ type: Object }) strings: any = strings
17
-
18
- /**
19
- * Runs on mount, used to set up various values and whatever you need to run
20
- */
21
- connectedCallback() {
22
- super.connectedCallback()
23
- }
24
- /**
25
- * Make sure the component renders in light DOM instead of shadow DOM
26
- */
27
- createRenderRoot() {
28
- return this
29
- }
30
-
31
- /**
32
- * Add support for Hot Module Reloading in dev mode
33
- */
34
- hotReplacedCallback() {
35
- this.requestUpdate()
36
- }
37
-
38
- /**
39
- * Go through changed properties and find ReactNodes to render out
40
- */
41
- protected update(changedProperties: PropertyValues) {
42
- changedProperties.forEach((_oldValue, propName) => {
43
- if (
44
- typeof propName === 'string' &&
45
- this[propName] &&
46
- typeof this[propName] === 'object' &&
47
- this[propName].$$typeof
48
- ) {
49
- this[propName] = renderReactNode(this[propName])
50
- }
51
- })
52
- super.update(changedProperties)
53
- }
54
-
55
- /**
56
- * Add extra stuff here whenever we decide what should be added here…
57
- */
58
- constructor() {
59
- super()
60
- }
61
- }
62
-
63
- /**
64
- * Base class for all Punkt input elements
65
- * @extends PktElement
66
- */
67
- export class PktInputElement extends PktElement {
68
- static get formAssociated() {
69
- return true
70
- }
71
-
72
- @property({ type: String, reflect: true })
73
- id: string = uuidish()
74
-
75
- @property({ type: String, reflect: true })
76
- name: string = ''
77
-
78
- @property({ type: Boolean, reflect: true })
79
- required: boolean = false
80
-
81
- @property({ type: Boolean, reflect: true })
82
- disabled: boolean = false
83
-
84
- @property({ type: String, reflect: true })
85
- placeholder: string = ''
86
-
87
- @property({ type: Number, reflect: true })
88
- min: string | number | null = null
89
-
90
- @property({ type: Number, reflect: true })
91
- max: string | number | null = null
92
-
93
- @property({ type: Number, reflect: true })
94
- minlength: number | null = 0
95
-
96
- @property({ type: Number, reflect: true })
97
- maxlength: number | null = 0
98
-
99
- @property({ type: String, reflect: true })
100
- pattern: string = ''
101
-
102
- @property({ type: Boolean, reflect: true })
103
- readonly: boolean = false
104
-
105
- @property({ type: String })
106
- ariaLabelledby: string | null = null
107
-
108
- @property({ type: String })
109
- ariaDescribedBy: string | null = null
110
-
111
- // Properties for InputWrapper
112
- @property({ type: String })
113
- label: string | null = null
114
-
115
- @property({ type: Boolean })
116
- inline: boolean = false
117
-
118
- @property({ type: Boolean })
119
- optionalTag: boolean = false
120
-
121
- @property({ type: String })
122
- optionalText: string = strings.forms.labels.optional
123
-
124
- @property({ type: Boolean })
125
- requiredTag: boolean = false
126
-
127
- @property({ type: String })
128
- requiredText: string = strings.forms.labels.required
129
-
130
- @property({ type: Boolean })
131
- hasError: boolean = false
132
-
133
- @property({ type: String })
134
- errorMessage: string = ''
135
-
136
- @property({ type: String })
137
- helptext: string = ''
138
-
139
- @property({ type: Boolean })
140
- counter: boolean = false
141
-
142
- @property({ type: Number })
143
- counterMaxLength: number = 0
144
-
145
- @property({ type: String })
146
- helptextDropdown: string = ''
147
-
148
- @property({ type: String })
149
- helptextDropdownButton: string | null = inputwrapperspecs.props.helptextDropdownButton.default
150
-
151
- @property({ type: Boolean, reflect: true })
152
- fullwidth: boolean = false
153
-
154
- @property({ type: Boolean })
155
- useWrapper: boolean = true
156
-
157
- @property({ type: String, attribute: 'data-testid' })
158
- dataTestid: string = ''
159
-
160
- @property({ type: Boolean })
161
- skipForwardTestid: boolean = false
162
-
163
- @state() touched: boolean = false
164
-
165
- constructor() {
166
- super()
167
- this.internals = this.attachInternals()
168
- }
169
-
170
- protected manageValidity(input: HTMLInputElement) {
171
- /**
172
- * This is where we define all the various validations and set the validity state
173
- */
174
- if (this.required && !this.value) {
175
- // If the input is required and the value is empty
176
- this.internals.setValidity({ valueMissing: true }, strings.forms.messages.required, input)
177
- } else if (input.validity.typeMismatch || input.validity.badInput) {
178
- // If the input type is wrong
179
- this.internals.setValidity({ typeMismatch: true }, strings.forms.messages.invalid, input)
180
- } else if (input.validity.patternMismatch) {
181
- // If the input pattern is wrong
182
- this.internals.setValidity(
183
- { patternMismatch: true },
184
- strings.forms.messages.invalidPattern,
185
- input,
186
- )
187
- } else if (
188
- input.validity.tooShort ||
189
- (this.minlength && this.minlength > 0 && this.value.length < this.minlength)
190
- ) {
191
- // If the input is too short or too few items selected
192
- this.internals.setValidity({ tooShort: true }, strings.forms.messages.tooShort, input)
193
- } else if (
194
- input.validity.tooLong ||
195
- (this.maxlength && this.maxlength > 0 && this.value.length > this.maxlength)
196
- ) {
197
- // If the input is too long or too many items selected
198
- this.internals.setValidity({ tooLong: true }, strings.forms.messages.tooLong, input)
199
- } else if (input.validity.rangeUnderflow) {
200
- // If the input is too low or date is too early
201
- this.internals.setValidity(
202
- { rangeUnderflow: true },
203
- strings.forms.messages.rangeUnderflow,
204
- input,
205
- )
206
- } else if (input.validity.rangeOverflow) {
207
- // If the input is too high or date is too late
208
- this.internals.setValidity(
209
- { rangeOverflow: true },
210
- strings.forms.messages.rangeOverflow,
211
- input,
212
- )
213
- } else if (input.validity.customError) {
214
- // If a custom error is set
215
- this.internals.setValidity({ customError: true }, input.validationMessage, input)
216
- } else {
217
- // If everything is fine
218
- this.internals.setValidity({})
219
- }
220
- }
221
-
222
- protected setFormValue(value: string | string[]): void {
223
- if (this.internals) {
224
- if (Array.isArray(value)) {
225
- const form = new FormData()
226
- value.forEach((v) => {
227
- form.append(this.name, v)
228
- })
229
- this.internals.setFormValue(form)
230
- } else {
231
- this.internals.setFormValue(value)
232
- }
233
- }
234
- }
235
-
236
- protected valueChanged(value: string | string[] | null, _old: string | string[] | null): void {
237
- if (_old !== this.value || _old !== this._value) {
238
- if (typeof value === 'string') {
239
- if ((this.multiple || this.range) && value.includes(',')) {
240
- value = value.split(',')
241
- }
242
- this.value = value
243
- this._value = Array.isArray(value) ? value : [value]
244
- } else if (Array.isArray(value)) {
245
- this.value = value
246
- this._value = value
247
- } else {
248
- this.value = ''
249
- this._value = []
250
- }
251
- if ((!this.value || this.value.length === 0) && _old && _old.length !== 0) {
252
- this.clearInputValue()
253
- } else if (this.value && this.value.toString() !== _old?.toString()) {
254
- this.onChange(this.value)
255
- }
256
- this.updateComplete.then(() => this.requestUpdate())
257
- }
258
- }
259
-
260
- // When input goes from content to no content
261
- protected clearInputValue(): void {
262
- const value = this.multiple || this.range ? [] : ''
263
- this.value = value
264
- this.internals.setFormValue(value)
265
- this.dispatchEvent(new Event('change'))
266
- this.dispatchEvent(
267
- new CustomEvent('value-change', {
268
- detail: value,
269
- bubbles: true,
270
- composed: true,
271
- }),
272
- )
273
- }
274
-
275
- // When user enters the input, we need to push that event out to the form
276
- protected onFocus(): void {
277
- this.dispatchEvent(new FocusEvent('focus'))
278
- }
279
-
280
- // And also when the user leaves the input...
281
- protected onBlur(): void {
282
- this.dispatchEvent(new FocusEvent('blur'))
283
- }
284
-
285
- // Trigger this when user types in the input
286
- protected onInput(): void {
287
- this.dispatchEvent(new InputEvent('input'))
288
- }
289
-
290
- // Trigger this when you want to set the value of the input out to the form
291
- protected onChange(value: string | string[]): void {
292
- if (!this.touched) {
293
- this.touched = true
294
- value && this.setFormValue(value)
295
- return
296
- }
297
- if (typeof value !== 'string' && !Array.isArray(value)) {
298
- return
299
- }
300
-
301
- if ((this.range || this.multiple) && !Array.isArray(value) && value.includes(',')) {
302
- value = value.split(',')
303
- }
304
-
305
- if (!this.multiple && !this.range && Array.isArray(value)) {
306
- value = value[0]
307
- }
308
-
309
- this.setFormValue(value)
310
-
311
- this.manageValidity(this.inputRef.value)
312
- if (this.inputRef2) {
313
- this.manageValidity(this.inputRef2.value)
314
- }
315
-
316
- // Change events
317
- this.dispatchEvent(new Event('change'))
318
- this.dispatchEvent(
319
- new CustomEvent('value-change', {
320
- detail: value,
321
- bubbles: true,
322
- composed: true,
323
- }),
324
- )
325
-
326
- this.internals.reportValidity()
327
- }
328
-
329
- protected updated(_changedProperties: PropertyValues): void {
330
- if (_changedProperties.has('dataTestid') && this.dataTestid && this.inputRef.value) {
331
- if (!this.skipForwardTestid) {
332
- this.inputRef.value.dataset.testid = this.dataTestid
333
- this.removeAttribute('data-testid')
334
- } else if (!this.hasAttribute('data-testid')) {
335
- this.setAttribute('data-testid', this.dataTestid)
336
- }
337
- }
338
- }
339
-
340
- protected firstUpdated(_changedProperties: PropertyValues): void {
341
- super.firstUpdated(_changedProperties)
342
-
343
- if (this.required) {
344
- this.internals.ariaRequired = true
345
- }
346
- if (this.disabled) {
347
- this.internals.ariaDisabled = true
348
- }
349
-
350
- this.internals.setFormValue(this.value)
351
- this.inputRef.value && this.manageValidity(this.inputRef.value)
352
- }
353
- }