@kth/style 0.0.12 → 0.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/README.md +28 -22
- package/dist/cjs/components/MenuPanel.d.ts +13 -0
- package/dist/cjs/index.d.ts +1 -5
- package/dist/cjs/index.js +63 -165
- package/dist/cjs/react.d.ts +1 -0
- package/dist/cjs/react.js +7 -0
- package/dist/esm/components/MenuPanel.d.ts +13 -0
- package/dist/esm/index.d.ts +1 -5
- package/dist/esm/index.js +63 -137
- package/dist/esm/react.d.ts +1 -0
- package/dist/esm/react.js +5 -0
- package/package.json +14 -14
- package/scss/components/a11y-nav.scss +31 -0
- package/scss/components/button.scss +20 -66
- package/scss/components/header.scss +40 -0
- package/scss/components/logotype.scss +28 -0
- package/scss/components/mega-menu.scss +33 -0
- package/scss/components/menu-item.scss +40 -0
- package/scss/components/menu-panel.scss +32 -0
- package/scss/components/search.scss +54 -0
- package/scss/components/visually-hidden.scss +11 -0
- package/scss/tokens/colors.scss +60 -0
- package/scss/tokens/icons.scss +69 -0
- package/scss/tokens/spacing.scss +31 -0
- package/scss/tokens/typography.scss +35 -0
- package/scss/utils/mixins.scss +19 -0
- package/scss/utils/prose.scss +88 -76
- package/scss/utils/reset.scss +59 -247
- package/dist/cjs/components/Button.d.ts +0 -20
- package/dist/cjs/components/Radio.d.ts +0 -20
- package/dist/cjs/components/Select.d.ts +0 -36
- package/dist/cjs/components/Tabs.d.ts +0 -34
- package/dist/cjs/icons/400/ArrowBack.d.ts +0 -3
- package/dist/cjs/icons/400/Check.d.ts +0 -3
- package/dist/cjs/icons/500/ArrowForward.d.ts +0 -3
- package/dist/cjs/stories/Button.stories.d.ts +0 -14
- package/dist/cjs/stories/ContentTabs.stories.d.ts +0 -13
- package/dist/cjs/stories/FilterTabs.stories.d.ts +0 -12
- package/dist/cjs/stories/InlineIcons.stories.d.ts +0 -9
- package/dist/cjs/stories/Select.stories.d.ts +0 -14
- package/dist/esm/components/Button.d.ts +0 -20
- package/dist/esm/components/Radio.d.ts +0 -20
- package/dist/esm/components/Select.d.ts +0 -36
- package/dist/esm/components/Tabs.d.ts +0 -34
- package/dist/esm/icons/400/ArrowBack.d.ts +0 -3
- package/dist/esm/icons/400/Check.d.ts +0 -3
- package/dist/esm/icons/500/ArrowForward.d.ts +0 -3
- package/dist/esm/stories/Button.stories.d.ts +0 -14
- package/dist/esm/stories/ContentTabs.stories.d.ts +0 -13
- package/dist/esm/stories/FilterTabs.stories.d.ts +0 -12
- package/dist/esm/stories/InlineIcons.stories.d.ts +0 -9
- package/dist/esm/stories/Select.stories.d.ts +0 -14
- package/scss/components/content-tabs.scss +0 -68
- package/scss/components/filter-tabs.scss +0 -31
- package/scss/components/form.scss +0 -48
- package/scss/components/inline-icon.scss +0 -7
- package/scss/globals.scss +0 -5
- package/scss/tokens/_colors.scss +0 -20
- package/scss/tokens/_spacing.en.md +0 -40
- package/scss/tokens/_spacing.scss +0 -81
- package/scss/tokens/_typography.scss +0 -71
- package/scss/tokens/index.scss +0 -6
- package/scss/utils/sizes.scss +0 -22
package/README.md
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
# @kth/style
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
Styles and components used across KTH.
|
|
4
|
+
|
|
5
|
+
Documentation available in the [KTH Style website](https://kthstyledemoref.z6.web.core.windows.net/style)
|
|
6
|
+
|
|
7
|
+
## Structure
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
@kth/style
|
|
11
|
+
├── src/
|
|
12
|
+
│ ├── index.ts
|
|
13
|
+
│ ├── components
|
|
14
|
+
│ └── react-components
|
|
15
|
+
├── scss/
|
|
16
|
+
│ ├── components
|
|
17
|
+
│ ├── tokens
|
|
18
|
+
│ └── utils
|
|
19
|
+
├── assets
|
|
20
|
+
├── ...
|
|
21
|
+
├── package.json
|
|
22
|
+
└── rollup.config.mjs
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- `scss` contains all CSS. Those can be imported as they are
|
|
26
|
+
- `src` contains source for JavaScript components. Written in JavaScript
|
|
27
|
+
- `src/components` are the components that do not use React
|
|
28
|
+
- `src/react-components` are the React components
|
|
29
|
+
- `index.ts` and `react.ts` re-export the content in the respective `components` directories
|
|
30
|
+
- `assets` are static assets like the fonts and logotype. This is meant to be exposed by apps using KTH Style
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Close all <dialog>s (modal and non-modal) in a document
|
|
3
|
+
*/
|
|
4
|
+
export declare function closeAllDialogs(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
7
|
+
* @param dialog A <dialog> element
|
|
8
|
+
*/
|
|
9
|
+
export declare function addEventListeners(dialog: HTMLDialogElement): void;
|
|
10
|
+
export declare class MenuPanel {
|
|
11
|
+
static init(container: HTMLElement | null, items: NodeListOf<Element>): void;
|
|
12
|
+
static initModal(items: NodeListOf<Element>): void;
|
|
13
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { Select, Option, OptionGroup } from "./components/Select";
|
|
3
|
-
export { BackButton, Button, ForwardButton } from "./components/Button";
|
|
4
|
-
export { default as IconArrowBack } from "./icons/400/ArrowBack";
|
|
5
|
-
export { default as IconCheck } from "./icons/400/Check";
|
|
1
|
+
export { MenuPanel } from "./components/MenuPanel";
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,179 +1,77 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.keys(e).forEach(function (k) {
|
|
9
|
-
if (k !== 'default') {
|
|
10
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () { return e[k]; }
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
n.default = e;
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
23
|
-
|
|
24
|
-
function getValueFromUrl(key) {
|
|
25
|
-
const url = new URL(location.href);
|
|
26
|
-
if (key) {
|
|
27
|
-
return url.searchParams.get(key);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return url.hash === "" ? null : url.hash.slice(1);
|
|
31
|
-
}
|
|
3
|
+
/**
|
|
4
|
+
* Close all <dialog>s (modal and non-modal) in a document
|
|
5
|
+
*/
|
|
6
|
+
function closeAllDialogs() {
|
|
7
|
+
document.querySelectorAll("dialog").forEach((dialog) => dialog.close());
|
|
32
8
|
}
|
|
33
9
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param
|
|
36
|
-
* @param key Query parameter to use. Hash if empty
|
|
37
|
-
* @param enableUrl Will sync with URL if true (this function behaves the same
|
|
38
|
-
* as `React.useState` if false)
|
|
10
|
+
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
11
|
+
* @param dialog A <dialog> element
|
|
39
12
|
*/
|
|
40
|
-
function
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
_setValue(getValueFromUrl(key) || defaultValue);
|
|
47
|
-
}
|
|
13
|
+
function addEventListeners(dialog) {
|
|
14
|
+
const closeButton = dialog.querySelector(".kth-button.close");
|
|
15
|
+
const backButton = dialog.querySelector(".kth-button.back");
|
|
16
|
+
dialog.addEventListener("keydown", (e) => {
|
|
17
|
+
if (e.key === "Escape") {
|
|
18
|
+
dialog.close();
|
|
48
19
|
}
|
|
49
|
-
window.addEventListener("popstate", updateValue);
|
|
50
|
-
return () => {
|
|
51
|
-
window.removeEventListener("popstate", updateValue);
|
|
52
|
-
};
|
|
53
20
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
if (enableUrl) {
|
|
64
|
-
history.pushState(undefined, "", url);
|
|
65
|
-
}
|
|
21
|
+
if (closeButton instanceof HTMLButtonElement) {
|
|
22
|
+
closeButton.addEventListener("click", () => {
|
|
23
|
+
closeAllDialogs();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (backButton instanceof HTMLButtonElement) {
|
|
27
|
+
backButton.addEventListener("click", () => {
|
|
28
|
+
dialog.close();
|
|
29
|
+
});
|
|
66
30
|
}
|
|
67
|
-
return [value, setValue];
|
|
68
31
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
32
|
+
class MenuPanel {
|
|
33
|
+
static init(container, items) {
|
|
34
|
+
if (!container)
|
|
35
|
+
return;
|
|
36
|
+
for (const item of items) {
|
|
37
|
+
if (!(item instanceof HTMLElement))
|
|
38
|
+
continue;
|
|
39
|
+
const dialog = item.nextElementSibling;
|
|
40
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
41
|
+
continue;
|
|
42
|
+
addEventListeners(dialog);
|
|
43
|
+
item.addEventListener("click", (e) => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
if (!dialog.open) {
|
|
46
|
+
closeAllDialogs();
|
|
47
|
+
dialog.show();
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
closeAllDialogs();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
container.addEventListener("focusout", function (e) {
|
|
55
|
+
const target = e.relatedTarget;
|
|
56
|
+
if (target && target instanceof Node && !container.contains(target)) {
|
|
57
|
+
closeAllDialogs();
|
|
82
58
|
}
|
|
83
|
-
|
|
84
|
-
case "Home":
|
|
85
|
-
setActiveTab(tabs[0].props.id);
|
|
86
|
-
break;
|
|
87
|
-
case "End":
|
|
88
|
-
setActiveTab(tabs[tabs.length - 1].props.id);
|
|
89
|
-
break;
|
|
59
|
+
});
|
|
90
60
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (activeTabIndex === -1) {
|
|
105
|
-
activeTabIndex = 0;
|
|
61
|
+
static initModal(items) {
|
|
62
|
+
for (const item of items) {
|
|
63
|
+
if (!(item instanceof HTMLElement))
|
|
64
|
+
continue;
|
|
65
|
+
const dialog = item.nextElementSibling;
|
|
66
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
67
|
+
continue;
|
|
68
|
+
addEventListeners(dialog);
|
|
69
|
+
item.addEventListener("click", (e) => {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
dialog.showModal();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
106
74
|
}
|
|
107
|
-
useFocus(ref.current?.querySelector(`#${activeTab}-tab`));
|
|
108
|
-
return (React.createElement(React.Fragment, null,
|
|
109
|
-
React.createElement("div", { ref: ref, className: `${classPrefix}`, id: id },
|
|
110
|
-
React.createElement("ul", { className: `${classPrefix}__tablist`, role: "tablist" }, children.map((child, index) => (React.createElement("li", { role: "presentation", className: `${classPrefix}__tab-element` },
|
|
111
|
-
React.createElement("button", { key: child.props.id, role: "tab", "aria-selected": index === activeTabIndex, "aria-controls": child.props.id, id: `${child.props.id}-tab`, className: `${classPrefix}__tab`, tabIndex: index === activeTabIndex ? 0 : -1, onKeyDown: (event) => {
|
|
112
|
-
handleKeyDown(event, index, children, setActiveTab);
|
|
113
|
-
}, onClick: (event) => {
|
|
114
|
-
event.preventDefault();
|
|
115
|
-
setActiveTab(child.props.id);
|
|
116
|
-
} }, child.props.title)))))),
|
|
117
|
-
children.map((child, index) => (React.createElement("div", { className: `${classPrefix}__tabpanel`, role: "tabpanel", "aria-labelledby": `${child.props.id}-tab`, id: child.props.id, key: index, hidden: index !== activeTabIndex }, child)))));
|
|
118
|
-
}
|
|
119
|
-
function NavigationTabs({ id, children, url = "query", defaultValue, }) {
|
|
120
|
-
return (React.createElement(GenericTabs, { id: id, children: children, url: url, defaultValue: defaultValue, classPrefix: "kth-navigation-tabs" }));
|
|
121
|
-
}
|
|
122
|
-
function ContentTabs({ id, children, url = "hash", defaultValue, }) {
|
|
123
|
-
return (React.createElement(GenericTabs, { id: id, children: children, url: url, defaultValue: defaultValue, classPrefix: "kth-content-tabs" }));
|
|
124
|
-
}
|
|
125
|
-
function Tab({ children }) {
|
|
126
|
-
return React.createElement(React.Fragment, null, children);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function Select({ name, label, description, value, onChange, children, error, }) {
|
|
130
|
-
const id = `select-${name}`;
|
|
131
|
-
return (React.createElement("div", { className: "kth-select" },
|
|
132
|
-
React.createElement("label", { htmlFor: id }, label),
|
|
133
|
-
description && React.createElement("p", { id: `${id}-description` }, description),
|
|
134
|
-
React.createElement("select", { id: id, "aria-describedby": description && `${id}-description`, name: name, value: value, onChange: (e) => onChange(e.target.value), "aria-invalid": error !== undefined ? "true" : "false" }, children),
|
|
135
|
-
error && (React.createElement("p", { className: "kth-select__error", role: "alert" }, error))));
|
|
136
|
-
}
|
|
137
|
-
function OptionGroup({ label, children }) {
|
|
138
|
-
return React.createElement("optgroup", { label: label }, children);
|
|
139
|
-
}
|
|
140
|
-
function Option({ value, children, disabled }) {
|
|
141
|
-
return (React.createElement("option", { value: value, disabled: disabled }, children));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const SvgArrowBack = (props) => (React__namespace.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1.25em", height: "1.25em", viewBox: "0 0 20 20", ...props },
|
|
145
|
-
React__namespace.createElement("path", { fill: "currentColor", d: "m10 16-6-6 6-6 1.063 1.063L6.875 9.25H16v1.5H6.875l4.188 4.188L10 16Z" })));
|
|
146
|
-
|
|
147
|
-
const SvgArrowForward = (props) => (React__namespace.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1.25em", height: "1.25em", viewBox: "0 0 20 20", ...props },
|
|
148
|
-
React__namespace.createElement("path", { fill: "currentColor", d: "m10 16.075-1.227-1.227 3.983-3.983h-8.83v-1.73h8.83L8.773 5.152 10 3.925 16.075 10 10 16.075Z" })));
|
|
149
|
-
|
|
150
|
-
/** A button with just text */
|
|
151
|
-
function Button({ children, onClick, appearance }) {
|
|
152
|
-
const className = ["kth-button", appearance].join(" ");
|
|
153
|
-
return (React.createElement("button", { onClick: onClick, className: className }, children));
|
|
154
|
-
}
|
|
155
|
-
function BackButton({ children, onClick }) {
|
|
156
|
-
return (React.createElement("button", { onClick: onClick, className: "kth-button tertiary" },
|
|
157
|
-
React.createElement(SvgArrowBack, null),
|
|
158
|
-
children));
|
|
159
75
|
}
|
|
160
|
-
function ForwardButton({ children, onClick }) {
|
|
161
|
-
return (React.createElement("button", { onClick: onClick, className: "kth-button primary" },
|
|
162
|
-
children,
|
|
163
|
-
React.createElement(SvgArrowForward, null)));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const SvgCheck = (props) => (React__namespace.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1.25em", height: "1.25em", viewBox: "0 0 20 20", ...props },
|
|
167
|
-
React__namespace.createElement("path", { fill: "currentColor", d: "M8.23 14.063 4.707 10.52 5.75 9.479l2.48 2.459 6.02-6L15.292 7l-7.063 7.063Z" })));
|
|
168
76
|
|
|
169
|
-
exports.
|
|
170
|
-
exports.Button = Button;
|
|
171
|
-
exports.ContentTabs = ContentTabs;
|
|
172
|
-
exports.ForwardButton = ForwardButton;
|
|
173
|
-
exports.IconArrowBack = SvgArrowBack;
|
|
174
|
-
exports.IconCheck = SvgCheck;
|
|
175
|
-
exports.NavigationTabs = NavigationTabs;
|
|
176
|
-
exports.Option = Option;
|
|
177
|
-
exports.OptionGroup = OptionGroup;
|
|
178
|
-
exports.Select = Select;
|
|
179
|
-
exports.Tab = Tab;
|
|
77
|
+
exports.MenuPanel = MenuPanel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function hello(): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Close all <dialog>s (modal and non-modal) in a document
|
|
3
|
+
*/
|
|
4
|
+
export declare function closeAllDialogs(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
7
|
+
* @param dialog A <dialog> element
|
|
8
|
+
*/
|
|
9
|
+
export declare function addEventListeners(dialog: HTMLDialogElement): void;
|
|
10
|
+
export declare class MenuPanel {
|
|
11
|
+
static init(container: HTMLElement | null, items: NodeListOf<Element>): void;
|
|
12
|
+
static initModal(items: NodeListOf<Element>): void;
|
|
13
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { Select, Option, OptionGroup } from "./components/Select";
|
|
3
|
-
export { BackButton, Button, ForwardButton } from "./components/Button";
|
|
4
|
-
export { default as IconArrowBack } from "./icons/400/ArrowBack";
|
|
5
|
-
export { default as IconCheck } from "./icons/400/Check";
|
|
1
|
+
export { MenuPanel } from "./components/MenuPanel";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,149 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
if (key) {
|
|
7
|
-
return url.searchParams.get(key);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
return url.hash === "" ? null : url.hash.slice(1);
|
|
11
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Close all <dialog>s (modal and non-modal) in a document
|
|
3
|
+
*/
|
|
4
|
+
function closeAllDialogs() {
|
|
5
|
+
document.querySelectorAll("dialog").forEach((dialog) => dialog.close());
|
|
12
6
|
}
|
|
13
7
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @param
|
|
16
|
-
* @param key Query parameter to use. Hash if empty
|
|
17
|
-
* @param enableUrl Will sync with URL if true (this function behaves the same
|
|
18
|
-
* as `React.useState` if false)
|
|
8
|
+
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
9
|
+
* @param dialog A <dialog> element
|
|
19
10
|
*/
|
|
20
|
-
function
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_setValue(getValueFromUrl(key) || defaultValue);
|
|
27
|
-
}
|
|
11
|
+
function addEventListeners(dialog) {
|
|
12
|
+
const closeButton = dialog.querySelector(".kth-button.close");
|
|
13
|
+
const backButton = dialog.querySelector(".kth-button.back");
|
|
14
|
+
dialog.addEventListener("keydown", (e) => {
|
|
15
|
+
if (e.key === "Escape") {
|
|
16
|
+
dialog.close();
|
|
28
17
|
}
|
|
29
|
-
window.addEventListener("popstate", updateValue);
|
|
30
|
-
return () => {
|
|
31
|
-
window.removeEventListener("popstate", updateValue);
|
|
32
|
-
};
|
|
33
18
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
if (enableUrl) {
|
|
44
|
-
history.pushState(undefined, "", url);
|
|
45
|
-
}
|
|
19
|
+
if (closeButton instanceof HTMLButtonElement) {
|
|
20
|
+
closeButton.addEventListener("click", () => {
|
|
21
|
+
closeAllDialogs();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (backButton instanceof HTMLButtonElement) {
|
|
25
|
+
backButton.addEventListener("click", () => {
|
|
26
|
+
dialog.close();
|
|
27
|
+
});
|
|
46
28
|
}
|
|
47
|
-
return [value, setValue];
|
|
48
29
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
30
|
+
class MenuPanel {
|
|
31
|
+
static init(container, items) {
|
|
32
|
+
if (!container)
|
|
33
|
+
return;
|
|
34
|
+
for (const item of items) {
|
|
35
|
+
if (!(item instanceof HTMLElement))
|
|
36
|
+
continue;
|
|
37
|
+
const dialog = item.nextElementSibling;
|
|
38
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
39
|
+
continue;
|
|
40
|
+
addEventListeners(dialog);
|
|
41
|
+
item.addEventListener("click", (e) => {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
if (!dialog.open) {
|
|
44
|
+
closeAllDialogs();
|
|
45
|
+
dialog.show();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
closeAllDialogs();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
container.addEventListener("focusout", function (e) {
|
|
53
|
+
const target = e.relatedTarget;
|
|
54
|
+
if (target && target instanceof Node && !container.contains(target)) {
|
|
55
|
+
closeAllDialogs();
|
|
62
56
|
}
|
|
63
|
-
|
|
64
|
-
case "Home":
|
|
65
|
-
setActiveTab(tabs[0].props.id);
|
|
66
|
-
break;
|
|
67
|
-
case "End":
|
|
68
|
-
setActiveTab(tabs[tabs.length - 1].props.id);
|
|
69
|
-
break;
|
|
57
|
+
});
|
|
70
58
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (activeTabIndex === -1) {
|
|
85
|
-
activeTabIndex = 0;
|
|
59
|
+
static initModal(items) {
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
if (!(item instanceof HTMLElement))
|
|
62
|
+
continue;
|
|
63
|
+
const dialog = item.nextElementSibling;
|
|
64
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
65
|
+
continue;
|
|
66
|
+
addEventListeners(dialog);
|
|
67
|
+
item.addEventListener("click", (e) => {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
dialog.showModal();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
86
72
|
}
|
|
87
|
-
useFocus(ref.current?.querySelector(`#${activeTab}-tab`));
|
|
88
|
-
return (React__default.createElement(React__default.Fragment, null,
|
|
89
|
-
React__default.createElement("div", { ref: ref, className: `${classPrefix}`, id: id },
|
|
90
|
-
React__default.createElement("ul", { className: `${classPrefix}__tablist`, role: "tablist" }, children.map((child, index) => (React__default.createElement("li", { role: "presentation", className: `${classPrefix}__tab-element` },
|
|
91
|
-
React__default.createElement("button", { key: child.props.id, role: "tab", "aria-selected": index === activeTabIndex, "aria-controls": child.props.id, id: `${child.props.id}-tab`, className: `${classPrefix}__tab`, tabIndex: index === activeTabIndex ? 0 : -1, onKeyDown: (event) => {
|
|
92
|
-
handleKeyDown(event, index, children, setActiveTab);
|
|
93
|
-
}, onClick: (event) => {
|
|
94
|
-
event.preventDefault();
|
|
95
|
-
setActiveTab(child.props.id);
|
|
96
|
-
} }, child.props.title)))))),
|
|
97
|
-
children.map((child, index) => (React__default.createElement("div", { className: `${classPrefix}__tabpanel`, role: "tabpanel", "aria-labelledby": `${child.props.id}-tab`, id: child.props.id, key: index, hidden: index !== activeTabIndex }, child)))));
|
|
98
|
-
}
|
|
99
|
-
function NavigationTabs({ id, children, url = "query", defaultValue, }) {
|
|
100
|
-
return (React__default.createElement(GenericTabs, { id: id, children: children, url: url, defaultValue: defaultValue, classPrefix: "kth-navigation-tabs" }));
|
|
101
|
-
}
|
|
102
|
-
function ContentTabs({ id, children, url = "hash", defaultValue, }) {
|
|
103
|
-
return (React__default.createElement(GenericTabs, { id: id, children: children, url: url, defaultValue: defaultValue, classPrefix: "kth-content-tabs" }));
|
|
104
|
-
}
|
|
105
|
-
function Tab({ children }) {
|
|
106
|
-
return React__default.createElement(React__default.Fragment, null, children);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function Select({ name, label, description, value, onChange, children, error, }) {
|
|
110
|
-
const id = `select-${name}`;
|
|
111
|
-
return (React__default.createElement("div", { className: "kth-select" },
|
|
112
|
-
React__default.createElement("label", { htmlFor: id }, label),
|
|
113
|
-
description && React__default.createElement("p", { id: `${id}-description` }, description),
|
|
114
|
-
React__default.createElement("select", { id: id, "aria-describedby": description && `${id}-description`, name: name, value: value, onChange: (e) => onChange(e.target.value), "aria-invalid": error !== undefined ? "true" : "false" }, children),
|
|
115
|
-
error && (React__default.createElement("p", { className: "kth-select__error", role: "alert" }, error))));
|
|
116
|
-
}
|
|
117
|
-
function OptionGroup({ label, children }) {
|
|
118
|
-
return React__default.createElement("optgroup", { label: label }, children);
|
|
119
|
-
}
|
|
120
|
-
function Option({ value, children, disabled }) {
|
|
121
|
-
return (React__default.createElement("option", { value: value, disabled: disabled }, children));
|
|
122
73
|
}
|
|
123
74
|
|
|
124
|
-
|
|
125
|
-
React.createElement("path", { fill: "currentColor", d: "m10 16-6-6 6-6 1.063 1.063L6.875 9.25H16v1.5H6.875l4.188 4.188L10 16Z" })));
|
|
126
|
-
|
|
127
|
-
const SvgArrowForward = (props) => (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1.25em", height: "1.25em", viewBox: "0 0 20 20", ...props },
|
|
128
|
-
React.createElement("path", { fill: "currentColor", d: "m10 16.075-1.227-1.227 3.983-3.983h-8.83v-1.73h8.83L8.773 5.152 10 3.925 16.075 10 10 16.075Z" })));
|
|
129
|
-
|
|
130
|
-
/** A button with just text */
|
|
131
|
-
function Button({ children, onClick, appearance }) {
|
|
132
|
-
const className = ["kth-button", appearance].join(" ");
|
|
133
|
-
return (React__default.createElement("button", { onClick: onClick, className: className }, children));
|
|
134
|
-
}
|
|
135
|
-
function BackButton({ children, onClick }) {
|
|
136
|
-
return (React__default.createElement("button", { onClick: onClick, className: "kth-button tertiary" },
|
|
137
|
-
React__default.createElement(SvgArrowBack, null),
|
|
138
|
-
children));
|
|
139
|
-
}
|
|
140
|
-
function ForwardButton({ children, onClick }) {
|
|
141
|
-
return (React__default.createElement("button", { onClick: onClick, className: "kth-button primary" },
|
|
142
|
-
children,
|
|
143
|
-
React__default.createElement(SvgArrowForward, null)));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const SvgCheck = (props) => (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1.25em", height: "1.25em", viewBox: "0 0 20 20", ...props },
|
|
147
|
-
React.createElement("path", { fill: "currentColor", d: "M8.23 14.063 4.707 10.52 5.75 9.479l2.48 2.459 6.02-6L15.292 7l-7.063 7.063Z" })));
|
|
148
|
-
|
|
149
|
-
export { BackButton, Button, ContentTabs, ForwardButton, SvgArrowBack as IconArrowBack, SvgCheck as IconCheck, NavigationTabs, Option, OptionGroup, Select, Tab };
|
|
75
|
+
export { MenuPanel };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function hello(): string;
|
package/package.json
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kth/style",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/esm/index.js",
|
|
9
|
+
"require": "./dist/cjs/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./react": {
|
|
12
|
+
"import": "./dist/esm/react.js",
|
|
13
|
+
"require": "./dist/cjs/react.js"
|
|
14
|
+
},
|
|
15
|
+
"./scss/*": "./scss/*"
|
|
16
|
+
},
|
|
6
17
|
"scripts": {
|
|
7
18
|
"clean": "rm -rf dist",
|
|
8
|
-
"
|
|
9
|
-
"build": "npm run clean && npm run build:components && npm run build:storybook",
|
|
19
|
+
"build": "npm run clean && npm run build:components",
|
|
10
20
|
"build:components": "rollup -c",
|
|
11
|
-
"build:storybook": "storybook build -o ../../apps/style-web/public/storybook",
|
|
12
21
|
"test": "npm run test:lint",
|
|
13
22
|
"test:lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
|
|
14
23
|
},
|
|
@@ -20,13 +29,6 @@
|
|
|
20
29
|
"@rollup/plugin-commonjs": "^24.1.0",
|
|
21
30
|
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
22
31
|
"@rollup/plugin-typescript": "^11.1.0",
|
|
23
|
-
"@storybook/addon-essentials": "^7.0.6",
|
|
24
|
-
"@storybook/addon-interactions": "^7.0.6",
|
|
25
|
-
"@storybook/addon-links": "^7.0.6",
|
|
26
|
-
"@storybook/blocks": "^7.0.6",
|
|
27
|
-
"@storybook/react": "^7.0.6",
|
|
28
|
-
"@storybook/react-vite": "^7.0.6",
|
|
29
|
-
"@storybook/testing-library": "^0.0.14-next.2",
|
|
30
32
|
"@types/react": "^18.0.28",
|
|
31
33
|
"@types/react-dom": "^18.0.11",
|
|
32
34
|
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
@@ -35,17 +37,15 @@
|
|
|
35
37
|
"eslint": "^8.38.0",
|
|
36
38
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
37
39
|
"eslint-plugin-react-refresh": "^0.3.4",
|
|
38
|
-
"eslint-plugin-storybook": "^0.6.11",
|
|
39
40
|
"prop-types": "^15.8.1",
|
|
40
41
|
"react": "^18.2.0",
|
|
41
42
|
"react-dom": "^18.2.0",
|
|
42
43
|
"rollup": "^3.21.4",
|
|
43
|
-
"storybook": "^7.0.6",
|
|
44
44
|
"typescript": "^5.0.2",
|
|
45
45
|
"vite": "^4.3.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": "*"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "2ef5d86944a2cd3c4eee7011c4b71983e11f309f"
|
|
51
51
|
}
|