@oslokommune/punkt-elements 12.37.6 → 12.38.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/card-CZG7XGlj.js +231 -0
  3. package/dist/card-Di1MQneh.cjs +87 -0
  4. package/dist/{checkbox-DCjl4VM0.js → checkbox-Ds1FrhqK.js} +1 -1
  5. package/dist/{checkbox-B7ObRUbU.cjs → checkbox-zqd3KVfz.cjs} +1 -1
  6. package/dist/{combobox-CnnTPWcA.js → combobox-B6x7Qukm.js} +1 -1
  7. package/dist/{combobox-BokBs9Jo.cjs → combobox-yUrUarU_.cjs} +1 -1
  8. package/dist/{datepicker-B767w-e9.cjs → datepicker-CH5ZmFhf.cjs} +1 -1
  9. package/dist/{datepicker-B-ytA8nG.js → datepicker-WpOJS948.js} +1 -1
  10. package/dist/index.d.ts +52 -4
  11. package/dist/{input-element-B5EvsMww.js → input-element-4hgBpSNJ.js} +28 -24
  12. package/dist/{input-element-KzKpjjLc.cjs → input-element-CwUniARD.cjs} +1 -1
  13. package/dist/pkt-card.cjs +1 -1
  14. package/dist/pkt-card.js +1 -1
  15. package/dist/pkt-checkbox.cjs +1 -1
  16. package/dist/pkt-checkbox.js +1 -1
  17. package/dist/pkt-combobox.cjs +1 -1
  18. package/dist/pkt-combobox.js +1 -1
  19. package/dist/pkt-datepicker.cjs +1 -1
  20. package/dist/pkt-datepicker.js +1 -1
  21. package/dist/pkt-index.cjs +1 -1
  22. package/dist/pkt-index.js +8 -8
  23. package/dist/pkt-radiobutton.cjs +1 -1
  24. package/dist/pkt-radiobutton.js +1 -1
  25. package/dist/pkt-select.cjs +1 -1
  26. package/dist/pkt-select.js +1 -1
  27. package/dist/pkt-textarea.cjs +1 -1
  28. package/dist/pkt-textarea.js +1 -1
  29. package/dist/pkt-textinput.cjs +1 -1
  30. package/dist/pkt-textinput.js +1 -1
  31. package/dist/{radiobutton-DP6RsaQc.cjs → radiobutton-CI2xaqAB.cjs} +2 -1
  32. package/dist/{radiobutton-DKHjKH75.js → radiobutton-CYJawqxD.js} +8 -7
  33. package/dist/{select-CQs_BAKs.cjs → select-BCL790jM.cjs} +1 -1
  34. package/dist/{select-ChsSC4Os.js → select-D3LR5zgE.js} +1 -1
  35. package/dist/{textarea-DAfViyIl.js → textarea-B8H6-8qY.js} +1 -1
  36. package/dist/{textarea-DIZf7CVg.cjs → textarea-DxbylapQ.cjs} +1 -1
  37. package/dist/{textinput-DMPRHokX.cjs → textinput-B__c4c1z.cjs} +1 -1
  38. package/dist/{textinput-u-UrLS8U.js → textinput-CPYLokFV.js} +1 -1
  39. package/package.json +3 -3
  40. package/src/components/card/card.ts +209 -40
  41. package/src/components/radiobutton/radiobutton.ts +1 -0
  42. package/dist/card-Cyww1yKr.js +0 -94
  43. package/dist/card-DH-3qNgp.cjs +0 -28
@@ -6,78 +6,247 @@ import { IPktTag } from '@/components/tag'
6
6
  import { PktElement } from '@/base-elements/element'
7
7
  import { PktSlotController } from '@/controllers/pkt-slot-controller'
8
8
  import { ref, createRef, Ref } from 'lit/directives/ref.js'
9
+ import { IPktHeading } from '../heading'
9
10
  import specs from 'componentSpecs/card.json'
10
11
  import '@/components/icon'
11
12
  import '@/components/tag'
13
+ import { IAriaAttributes } from '@/types/aria'
12
14
 
13
- export type TCardSkin = 'outlined' | 'gray' | 'beige' | 'green' | 'blue'
15
+ export type TCardSkin = 'outlined' | 'outlined-beige' | 'gray' | 'beige' | 'green' | 'blue'
14
16
  export type TDirection = 'portrait' | 'landscape'
17
+ export type TCardPadding = 'none' | 'standard'
18
+ export type TCardImageShape = 'square' | 'round'
19
+ export type TCardTagPosition = 'top' | 'bottom'
20
+
21
+ export interface IPktCard {
22
+ ariaLabel?: IAriaAttributes['aria-label']
23
+ author?: string | null
24
+ date?: string | null
25
+ direction?: TDirection
26
+ heading?: string
27
+ headingLevel?: IPktHeading['level']
28
+ image?: { src: string; alt: string }
29
+ imageShape?: TCardImageShape
30
+ clickCardLink?: string | null
31
+ openLinkInNewTab?: boolean | null
32
+ borderOnHover?: boolean | null
33
+ padding?: TCardPadding
34
+ skin?: TCardSkin
35
+ subheading?: string
36
+ tagPosition?: TCardTagPosition
37
+ tags?: (Omit<IPktTag, 'closeTag'> & { text: string })[]
38
+ }
15
39
 
16
40
  @customElement('pkt-card')
17
- export class PktCard extends PktElement {
41
+ export class PktCard extends PktElement implements IPktCard {
42
+ // Refs
43
+
18
44
  defaultSlot: Ref<HTMLElement> = createRef()
19
45
 
46
+ //Constructor
47
+
20
48
  constructor() {
21
49
  super()
22
50
  this.slotController = new PktSlotController(this, this.defaultSlot)
23
51
  }
24
52
 
25
- @property({ type: String, reflect: true }) skin: TCardSkin = specs.props.skin.default as TCardSkin
26
- @property({ type: String, reflect: true }) direction: TDirection = specs.props.direction
27
- .default as TDirection
28
- @property({ type: Object, reflect: true }) image: { src: string; alt: string } = {
53
+ // Properties
54
+
55
+ @property({ type: String }) ariaLabel: string = ''
56
+ @property({ type: String }) author: string | null = null
57
+ @property({ type: Boolean }) borderOnHover: boolean = true
58
+ @property({ type: String, reflect: true }) clickCardLink: IPktCard['clickCardLink'] = null
59
+ @property({ type: String }) date: string | null = null
60
+ @property({ type: String }) direction: TDirection = specs.props.direction.default as TDirection
61
+ @property({ type: String }) heading: string = ''
62
+ @property({ type: Number }) headinglevel: IPktHeading['level'] = 3
63
+ @property({ type: Object }) image: { src: string; alt: string } = {
29
64
  src: '',
30
65
  alt: '',
31
66
  }
32
- @property({ type: String, reflect: true }) heading: string = ''
33
- @property({ type: String, reflect: true }) subheading: string = ''
34
- @property({ type: Array, reflect: true }) tags: (Omit<IPktTag, 'closeTag'> & { text: string })[] =
35
- []
67
+ @property({ type: String }) imageShape: TCardImageShape = 'square'
68
+ @property({ type: Boolean }) openLinkInNewTab: boolean = false
69
+ @property({ type: String }) padding: TCardPadding = specs.props.padding.default as TCardPadding
70
+ @property({ type: String }) skin: TCardSkin = specs.props.skin.default as TCardSkin
71
+ @property({ type: String }) subheading: string = ''
72
+ @property({ type: String }) tagPosition: 'top' | 'bottom' = 'top'
73
+ @property({ type: Array }) tags: (Omit<IPktTag, 'closeTag'> & { text: string })[] = []
36
74
 
37
75
  connectedCallback() {
38
76
  super.connectedCallback()
39
77
  }
40
78
 
79
+ // Render methods
80
+
81
+ // Main render method
82
+ // prettier-ignore
41
83
  render() {
42
84
  const classes = {
43
85
  'pkt-card': true,
44
86
  [`pkt-card--${this.skin}`]: this.skin,
45
87
  [`pkt-card--${this.direction}`]: this.direction,
88
+ [`pkt-card--padding-${this.padding}`]: this.padding,
89
+ [`pkt-card--border-on-hover`]: this.borderOnHover,
90
+
46
91
  }
47
92
 
93
+ //
94
+ const ariaLabelLenke =
95
+ this.ariaLabel?.trim() || (this.heading ? `${this.heading} lenkekort` : 'lenkekort')
96
+ const ariaLabelVanlig = this.ariaLabel?.trim() || (this.heading ? this.heading : 'kort')
97
+
48
98
  return html`
49
- <div class=${classMap(classes)}>
50
- ${this.image.src &&
51
- html`
52
- <div class="pkt-card__image">
53
- <img src=${this.image.src} alt=${this.image.alt || ''} />
54
- </div>
55
- `}
99
+ <article
100
+ class=${classMap(classes)}
101
+ aria-label=${ifDefined(this.clickCardLink ? ariaLabelLenke : ariaLabelVanlig)}
102
+ >
103
+ ${this.renderImage()}
56
104
  <div class="pkt-card__wrapper">
57
- ${this.tags.length > 0
58
- ? html`
59
- <div class="pkt-card__tags">
60
- ${this.tags.map(
61
- (tag) => html`
62
- <pkt-tag
63
- textStyle="normal-text"
64
- size="medium"
65
- skin=${ifDefined(tag.skin)}
66
- iconName=${ifDefined(tag.iconName)}
67
- >
68
- ${tag.text}
69
- </pkt-tag>
70
- `,
71
- )}
72
- </div>
73
- `
74
- : nothing}
75
- ${this.heading && html`<h3 class="pkt-txt-30-medium">${this.heading}</h3>`}
76
- ${this.subheading && html`<p class="pkt-txt-20-light">${this.subheading}</p>`}
77
- ${this.defaultSlot &&
78
- html`<div class="pkt-card__content" ${ref(this.defaultSlot)}></div>`}
105
+ ${this.tagPosition === 'top' ? this.renderTags() : nothing}
106
+ ${this.renderHeader()}
107
+ ${this.renderSlot()}
108
+ ${this.tagPosition === 'bottom' ? this.renderTags() : nothing}
109
+ ${this.renderCreditline()}
110
+ </div>
111
+ </article>
112
+ `
113
+ }
114
+
115
+ // Render methods for different parts of the card
116
+ renderImage() {
117
+ const imageClasses = {
118
+ 'pkt-card__image': true,
119
+ [`pkt-card__image-${this.imageShape}`]: this.imageShape,
120
+ }
121
+
122
+ return html`
123
+ ${this.image.src &&
124
+ html`
125
+ <div class=${classMap(imageClasses)}>
126
+ <img src=${this.image.src} alt=${this.image.alt || ''} />
79
127
  </div>
80
- </div>
128
+ `}
129
+ `
130
+ }
131
+
132
+ // Do not render heading if link is present, render link heading instead
133
+ // Combine the rendering for headings into a renderHeader method
134
+ renderHeading() {
135
+ return html`
136
+ ${this.heading && !this.clickCardLink
137
+ ? html`
138
+ <pkt-heading
139
+ class="pkt-card__heading"
140
+ .level=${this.headinglevel || 3}
141
+ size="medium"
142
+ nospacing
143
+ >
144
+ ${this.heading}
145
+ </pkt-heading>
146
+ `
147
+ : nothing}
148
+ `
149
+ }
150
+
151
+ renderLinkHeading() {
152
+ return html`
153
+ ${this.clickCardLink
154
+ ? html`
155
+ <pkt-heading
156
+ class="pkt-card__link-heading pkt-card__heading"
157
+ .level=${this.headinglevel || 3}
158
+ size="medium"
159
+ nospacing
160
+ >
161
+ <a
162
+ class="pkt-card__link"
163
+ href=${this.clickCardLink}
164
+ target=${this.openLinkInNewTab ? '_blank' : '_self'}
165
+ >${this.heading}</a
166
+ >
167
+ </pkt-heading>
168
+ `
169
+ : nothing}
170
+ `
171
+ }
172
+
173
+ renderSubheading() {
174
+ return html`
175
+ ${this.subheading ? html` <p class="pkt-card__subheading ">${this.subheading}</p> ` : nothing}
176
+ `
177
+ }
178
+
179
+ // Render header
180
+
181
+ // prettier-ignore
182
+ renderHeader() {
183
+ const hasHeading = !!this.heading || !!this.subheading
184
+ return html`
185
+ ${hasHeading
186
+ ? html`
187
+ <header class="pkt-card__header">
188
+ ${this.renderHeading()}
189
+ ${this.renderLinkHeading()}
190
+ ${this.renderSubheading()}
191
+ </header>
192
+ `
193
+ : nothing}
194
+ `
195
+ }
196
+
197
+ renderTags() {
198
+ const tagClasses = {
199
+ 'pkt-card__tags': true,
200
+ [`pkt-card__tags-${this.tagPosition}`]: this.tagPosition,
201
+ }
202
+ return html`
203
+ ${this.tags.length > 0
204
+ ? html`
205
+ <div
206
+ class=${classMap(tagClasses)}
207
+ role="list"
208
+ aria-label=${this.tags.length > 1 ? 'merkelapper' : 'merkelapp'}
209
+ >
210
+ ${this.tags.map(
211
+ (tag) => html`
212
+ <pkt-tag
213
+ role="listitem"
214
+ textStyle="normal-text"
215
+ size="medium"
216
+ skin=${ifDefined(tag.skin)}
217
+ iconName=${ifDefined(tag.iconName)}
218
+ >
219
+ ${tag.text}
220
+ </pkt-tag>
221
+ `,
222
+ )}
223
+ </div>
224
+ `
225
+ : nothing}
226
+ `
227
+ }
228
+
229
+ renderSlot() {
230
+ return html`
231
+ ${this.defaultSlot &&
232
+ html`<section class="pkt-card__content" ${ref(this.defaultSlot)}></section>`}
233
+ `
234
+ }
235
+
236
+ renderCreditline() {
237
+ return html`
238
+ ${this.author || this.date
239
+ ? html`
240
+ <footer class="pkt-card__creditline">
241
+ ${this.author
242
+ ? html`<span class="pkt-card__creditline-author">${this.author}</span>`
243
+ : nothing}
244
+ ${this.date
245
+ ? html`<span class="pkt-card__creditline-date">${this.date}</span>`
246
+ : nothing}
247
+ </footer>
248
+ `
249
+ : nothing}
81
250
  `
82
251
  }
83
252
  }
@@ -67,6 +67,7 @@ export class PktRadioButton extends PktInputElement {
67
67
  type="radio"
68
68
  role="radio"
69
69
  ?disabled=${this.disabled}
70
+ form=""
70
71
  name=${this.name + '-internal'}
71
72
  ${ref(this.inputRef)}
72
73
  @change=${this.toggleChecked}
@@ -1,94 +0,0 @@
1
- import { e as m } from "./class-map-KyMqi0fa.js";
2
- import { o as d } from "./if-defined-BErSJCeJ.js";
3
- import { P as u, E as g, x as i, n as a, a as f } from "./element-DjjF_tEh.js";
4
- import { P as k } from "./pkt-slot-controller-DtDaD9q_.js";
5
- import { e as $, n as v } from "./ref-iIffqQAI.js";
6
- import "./icon-Beoxup8E.js";
7
- import "./tag-Cu8afZy8.js";
8
- const y = {
9
- skin: {
10
- default: "outlined"
11
- },
12
- direction: {
13
- default: "portrait"
14
- }
15
- }, h = {
16
- props: y
17
- };
18
- var _ = Object.defineProperty, P = Object.getOwnPropertyDescriptor, r = (o, t, n, p) => {
19
- for (var s = p > 1 ? void 0 : p ? P(t, n) : t, c = o.length - 1, l; c >= 0; c--)
20
- (l = o[c]) && (s = (p ? l(t, n, s) : l(s)) || s);
21
- return p && s && _(t, n, s), s;
22
- };
23
- let e = class extends u {
24
- constructor() {
25
- super(), this.defaultSlot = $(), this.skin = h.props.skin.default, this.direction = h.props.direction.default, this.image = {
26
- src: "",
27
- alt: ""
28
- }, this.heading = "", this.subheading = "", this.tags = [], this.slotController = new k(this, this.defaultSlot);
29
- }
30
- connectedCallback() {
31
- super.connectedCallback();
32
- }
33
- render() {
34
- const o = {
35
- "pkt-card": !0,
36
- [`pkt-card--${this.skin}`]: this.skin,
37
- [`pkt-card--${this.direction}`]: this.direction
38
- };
39
- return i`
40
- <div class=${m(o)}>
41
- ${this.image.src && i`
42
- <div class="pkt-card__image">
43
- <img src=${this.image.src} alt=${this.image.alt || ""} />
44
- </div>
45
- `}
46
- <div class="pkt-card__wrapper">
47
- ${this.tags.length > 0 ? i`
48
- <div class="pkt-card__tags">
49
- ${this.tags.map(
50
- (t) => i`
51
- <pkt-tag
52
- textStyle="normal-text"
53
- size="medium"
54
- skin=${d(t.skin)}
55
- iconName=${d(t.iconName)}
56
- >
57
- ${t.text}
58
- </pkt-tag>
59
- `
60
- )}
61
- </div>
62
- ` : g}
63
- ${this.heading && i`<h3 class="pkt-txt-30-medium">${this.heading}</h3>`}
64
- ${this.subheading && i`<p class="pkt-txt-20-light">${this.subheading}</p>`}
65
- ${this.defaultSlot && i`<div class="pkt-card__content" ${v(this.defaultSlot)}></div>`}
66
- </div>
67
- </div>
68
- `;
69
- }
70
- };
71
- r([
72
- a({ type: String, reflect: !0 })
73
- ], e.prototype, "skin", 2);
74
- r([
75
- a({ type: String, reflect: !0 })
76
- ], e.prototype, "direction", 2);
77
- r([
78
- a({ type: Object, reflect: !0 })
79
- ], e.prototype, "image", 2);
80
- r([
81
- a({ type: String, reflect: !0 })
82
- ], e.prototype, "heading", 2);
83
- r([
84
- a({ type: String, reflect: !0 })
85
- ], e.prototype, "subheading", 2);
86
- r([
87
- a({ type: Array, reflect: !0 })
88
- ], e.prototype, "tags", 2);
89
- e = r([
90
- f("pkt-card")
91
- ], e);
92
- export {
93
- e as P
94
- };
@@ -1,28 +0,0 @@
1
- "use strict";const h=require("./class-map-DCyaICmy.cjs"),d=require("./if-defined-a3sotaUr.cjs"),t=require("./element-BSypUpzA.cjs"),u=require("./pkt-slot-controller-Da-RgXfS.cjs"),l=require("./ref-BvbyvXRH.cjs");require("./icon-BnKGwYjj.cjs");require("./tag-B9kFYxHg.cjs");const k={skin:{default:"outlined"},direction:{default:"portrait"}},p={props:k};var g=Object.defineProperty,f=Object.getOwnPropertyDescriptor,s=(n,i,e,a)=>{for(var r=a>1?void 0:a?f(i,e):i,c=n.length-1,o;c>=0;c--)(o=n[c])&&(r=(a?o(i,e,r):o(r))||r);return a&&r&&g(i,e,r),r};exports.PktCard=class extends t.PktElement{constructor(){super(),this.defaultSlot=l.e(),this.skin=p.props.skin.default,this.direction=p.props.direction.default,this.image={src:"",alt:""},this.heading="",this.subheading="",this.tags=[],this.slotController=new u.PktSlotController(this,this.defaultSlot)}connectedCallback(){super.connectedCallback()}render(){const i={"pkt-card":!0,[`pkt-card--${this.skin}`]:this.skin,[`pkt-card--${this.direction}`]:this.direction};return t.x`
2
- <div class=${h.e(i)}>
3
- ${this.image.src&&t.x`
4
- <div class="pkt-card__image">
5
- <img src=${this.image.src} alt=${this.image.alt||""} />
6
- </div>
7
- `}
8
- <div class="pkt-card__wrapper">
9
- ${this.tags.length>0?t.x`
10
- <div class="pkt-card__tags">
11
- ${this.tags.map(e=>t.x`
12
- <pkt-tag
13
- textStyle="normal-text"
14
- size="medium"
15
- skin=${d.o(e.skin)}
16
- iconName=${d.o(e.iconName)}
17
- >
18
- ${e.text}
19
- </pkt-tag>
20
- `)}
21
- </div>
22
- `:t.E}
23
- ${this.heading&&t.x`<h3 class="pkt-txt-30-medium">${this.heading}</h3>`}
24
- ${this.subheading&&t.x`<p class="pkt-txt-20-light">${this.subheading}</p>`}
25
- ${this.defaultSlot&&t.x`<div class="pkt-card__content" ${l.n(this.defaultSlot)}></div>`}
26
- </div>
27
- </div>
28
- `}};s([t.n({type:String,reflect:!0})],exports.PktCard.prototype,"skin",2);s([t.n({type:String,reflect:!0})],exports.PktCard.prototype,"direction",2);s([t.n({type:Object,reflect:!0})],exports.PktCard.prototype,"image",2);s([t.n({type:String,reflect:!0})],exports.PktCard.prototype,"heading",2);s([t.n({type:String,reflect:!0})],exports.PktCard.prototype,"subheading",2);s([t.n({type:Array,reflect:!0})],exports.PktCard.prototype,"tags",2);exports.PktCard=s([t.t("pkt-card")],exports.PktCard);