@oslokommune/punkt-css 11.1.1 → 11.2.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 +18 -0
- package/README.md +1 -0
- package/dist/css/components/tabs.css +80 -0
- package/dist/css/components/tabs.min.css +1 -0
- package/dist/css/components/textinput.css +1 -1
- package/dist/css/components/textinput.min.css +1 -1
- package/dist/css/pkt-base.css +4 -3
- package/dist/css/pkt-base.min.css +1 -1
- package/dist/css/pkt-components.css +82 -1
- package/dist/css/pkt-components.min.css +1 -1
- package/dist/css/pkt-elements.css +2 -2
- package/dist/css/pkt-elements.min.css +1 -1
- package/dist/css/pkt.css +87 -5
- package/dist/css/pkt.min.css +1 -1
- package/dist/scripts/pkt-tabs.js +88 -0
- package/dist/scss/abstracts/variables/_index.scss +1 -1
- package/dist/scss/base/_containers.scss +1 -0
- package/dist/scss/base/_typography.scss +1 -1
- package/dist/scss/components/_index.scss +1 -0
- package/dist/scss/components/_tabs.scss +93 -0
- package/package.json +2 -2
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export default class PktTabs {
|
|
2
|
+
/*
|
|
3
|
+
* Punkt Tabs
|
|
4
|
+
* Inspired by the tabs example in the ARIA Authoring Practices Guide from W3C
|
|
5
|
+
* https://www.w3.org/WAI/ARIA/apg/patterns/tabs/
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
constructor(tabListNode, panelNode = null) {
|
|
9
|
+
this.tabs = Array.from(tabListNode.querySelectorAll('[role=tab]'))
|
|
10
|
+
this.panels = panelNode
|
|
11
|
+
? Array.from(panelNode.querySelectorAll('[role=tabpanel]'))
|
|
12
|
+
: []
|
|
13
|
+
this.first = this.tabs[0]
|
|
14
|
+
this.last = this.tabs[this.tabs.length - 1]
|
|
15
|
+
this.current = this.first
|
|
16
|
+
|
|
17
|
+
for (var i = 0; i < this.tabs.length; i++) {
|
|
18
|
+
var tab = this.tabs[i]
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
tab.getAttribute('aria-selected') === 'true' ||
|
|
22
|
+
tab.classList.contains('active')
|
|
23
|
+
) {
|
|
24
|
+
this.current = tab
|
|
25
|
+
}
|
|
26
|
+
tab.addEventListener('keydown', this.onKeydown.bind(this))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.setActive(this.current)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setActive(current) {
|
|
33
|
+
for (var i = 0; i < this.tabs.length; i++) {
|
|
34
|
+
var tab = this.tabs[i]
|
|
35
|
+
if (current === tab) {
|
|
36
|
+
tab.setAttribute('aria-selected', 'true')
|
|
37
|
+
tab.removeAttribute('tabindex')
|
|
38
|
+
tab.classList.add('active')
|
|
39
|
+
this.panels.length && this.panels[i].classList.remove('pkt-hide')
|
|
40
|
+
} else {
|
|
41
|
+
tab.setAttribute('aria-selected', 'false')
|
|
42
|
+
tab.setAttribute('tabindex', '-1')
|
|
43
|
+
tab.classList.remove('active')
|
|
44
|
+
this.panels.length && this.panels[i].classList.add('pkt-hide')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setActiveByIndex(index) {
|
|
50
|
+
this.setActive(this.tabs[index])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
previous(current) {
|
|
54
|
+
current !== this.first && this.tabs[this.tabs.indexOf(current) - 1].focus()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
next(current) {
|
|
58
|
+
current !== this.last && this.tabs[this.tabs.indexOf(current) + 1].focus()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
onKeydown(event) {
|
|
62
|
+
var target = event.currentTarget
|
|
63
|
+
var hasInteracted = false
|
|
64
|
+
|
|
65
|
+
switch (event.code) {
|
|
66
|
+
case 'ArrowLeft':
|
|
67
|
+
this.previous(target)
|
|
68
|
+
hasInteracted = true
|
|
69
|
+
break
|
|
70
|
+
case 'ArrowRight':
|
|
71
|
+
this.next(target)
|
|
72
|
+
hasInteracted = true
|
|
73
|
+
break
|
|
74
|
+
case 'ArrowDown':
|
|
75
|
+
case 'Space':
|
|
76
|
+
target.click()
|
|
77
|
+
hasInteracted = true
|
|
78
|
+
break
|
|
79
|
+
default:
|
|
80
|
+
break
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (hasInteracted) {
|
|
84
|
+
event.stopPropagation()
|
|
85
|
+
event.preventDefault()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
@use 'sass:map';
|
|
2
|
+
@use '../abstracts/variables';
|
|
3
|
+
@use '../abstracts/mixins/typography';
|
|
4
|
+
|
|
5
|
+
.pkt-tabs {
|
|
6
|
+
--pkt-tabs-bg: var(--pkt-color-background-default);
|
|
7
|
+
background-color: var(--pkt-tabs-bg);
|
|
8
|
+
position: relative;
|
|
9
|
+
border-bottom: 1px solid var(--pkt-color-border-gray);
|
|
10
|
+
&__list {
|
|
11
|
+
position: relative;
|
|
12
|
+
width: auto;
|
|
13
|
+
width: 100%;
|
|
14
|
+
overflow-x: scroll;
|
|
15
|
+
scrollbar-width: thin;
|
|
16
|
+
padding: 0.25rem 4rem 0 0.25rem;
|
|
17
|
+
margin: 0;
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-wrap: nowrap;
|
|
20
|
+
align-items: flex-start;
|
|
21
|
+
}
|
|
22
|
+
&__button {
|
|
23
|
+
border: 0;
|
|
24
|
+
padding: 0;
|
|
25
|
+
background: none;
|
|
26
|
+
border-radius: 0;
|
|
27
|
+
}
|
|
28
|
+
&__link,
|
|
29
|
+
&__button {
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
gap: 0.5rem;
|
|
34
|
+
padding: 0.75rem 1rem;
|
|
35
|
+
color: var(--pkt-color-text-action-disabled);
|
|
36
|
+
border-bottom: 0.25rem solid transparent;
|
|
37
|
+
@include typography.get-text('pkt-txt-16');
|
|
38
|
+
white-space: nowrap;
|
|
39
|
+
.pkt-icon {
|
|
40
|
+
--fg-color: currentColor;
|
|
41
|
+
}
|
|
42
|
+
&,
|
|
43
|
+
&:hover,
|
|
44
|
+
&:active {
|
|
45
|
+
text-decoration: none;
|
|
46
|
+
}
|
|
47
|
+
&:focus:not(:active),
|
|
48
|
+
&:focus-visible:not(:active) {
|
|
49
|
+
border: 0;
|
|
50
|
+
box-shadow: none;
|
|
51
|
+
background-color: var(--pkt-color-surface-default-gray);
|
|
52
|
+
outline: 0.25rem solid var(--pkt-color-border-states-focus);
|
|
53
|
+
outline-offset: 0;
|
|
54
|
+
}
|
|
55
|
+
&.active:focus,
|
|
56
|
+
&.active:focus-visible {
|
|
57
|
+
box-shadow: none;
|
|
58
|
+
border-bottom: 0.25rem solid var(--pkt-color-border-blue);
|
|
59
|
+
}
|
|
60
|
+
&:hover,
|
|
61
|
+
&:focus,
|
|
62
|
+
&:focus-visible,
|
|
63
|
+
&:focus-visible:is(:active),
|
|
64
|
+
&:focus:is(:active),
|
|
65
|
+
&:active {
|
|
66
|
+
outline: 0;
|
|
67
|
+
color: var(--pkt-color-text-action-active);
|
|
68
|
+
border-bottom: 0.25rem solid var(--pkt-color-border-states-hover);
|
|
69
|
+
}
|
|
70
|
+
&.active {
|
|
71
|
+
color: var(--pkt-color-text-action-normal);
|
|
72
|
+
border-bottom: 0.25rem solid var(--pkt-color-border-blue);
|
|
73
|
+
@include typography.get-text('pkt-txt-16-medium');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&:after {
|
|
78
|
+
content: '';
|
|
79
|
+
display: block;
|
|
80
|
+
position: absolute;
|
|
81
|
+
z-index: 3;
|
|
82
|
+
background: linear-gradient(
|
|
83
|
+
90deg,
|
|
84
|
+
transparent 0%,
|
|
85
|
+
var(--pkt-color-background-default) 100%
|
|
86
|
+
);
|
|
87
|
+
top: 0;
|
|
88
|
+
right: 0;
|
|
89
|
+
bottom: 0;
|
|
90
|
+
width: 5rem;
|
|
91
|
+
pointer-events: none;
|
|
92
|
+
}
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-css",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.2.0",
|
|
4
4
|
"description": "CSS-rammeverket til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
56
56
|
},
|
|
57
57
|
"license": "MIT",
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "fec4dbecc80967363e57146603fd5618b107c879"
|
|
59
59
|
}
|