@kth/style 0.0.8 → 0.0.10

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.
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ interface ButtonProps {
3
+ /** The label of the button */
4
+ children?: string;
5
+ /** The callback function when the button is clicked */
6
+ onClick?: () => void;
7
+ /** Appearance */
8
+ appearance: "primary" | "secondary" | "tertiary";
9
+ }
10
+ interface IconButtonProps {
11
+ /** The label of the button */
12
+ children?: string;
13
+ /** The callback function when the button is clicked */
14
+ onClick?: () => void;
15
+ }
16
+ /** A button with just text */
17
+ export declare function Button({ children, onClick, appearance }: ButtonProps): JSX.Element;
18
+ export declare function BackButton({ children, onClick }: IconButtonProps): JSX.Element;
19
+ export declare function ForwardButton({ children, onClick }: IconButtonProps): JSX.Element;
20
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { SVGProps } from "react";
2
+ declare const SvgArrowBack: (props: SVGProps<SVGSVGElement>) => JSX.Element;
3
+ export default SvgArrowBack;
@@ -0,0 +1,3 @@
1
+ import type { SVGProps } from "react";
2
+ declare const SvgCheck: (props: SVGProps<SVGSVGElement>) => JSX.Element;
3
+ export default SvgCheck;
@@ -0,0 +1,3 @@
1
+ import type { SVGProps } from "react";
2
+ declare const SvgArrowForward: (props: SVGProps<SVGSVGElement>) => JSX.Element;
3
+ export default SvgArrowForward;
@@ -1,2 +1,5 @@
1
1
  export { Tab, ContentTabs, NavigationTabs } from "./components/Tabs";
2
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";
package/dist/cjs/index.js CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  var React = require('react');
4
4
 
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
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
+
5
24
  function getValueFromUrl(key) {
6
25
  const url = new URL(location.href);
7
26
  if (key) {
@@ -122,7 +141,37 @@ function Option({ value, children }) {
122
141
  return React.createElement("option", { value: value }, children);
123
142
  }
124
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
+ }
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
+
169
+ exports.BackButton = BackButton;
170
+ exports.Button = Button;
125
171
  exports.ContentTabs = ContentTabs;
172
+ exports.ForwardButton = ForwardButton;
173
+ exports.IconArrowBack = SvgArrowBack;
174
+ exports.IconCheck = SvgCheck;
126
175
  exports.NavigationTabs = NavigationTabs;
127
176
  exports.Option = Option;
128
177
  exports.OptionGroup = OptionGroup;
@@ -0,0 +1,14 @@
1
+ import type { StoryObj } from "@storybook/react";
2
+ import { Button } from "../components/Button";
3
+ import "../../scss/globals.scss";
4
+ import "../../scss/components/button.scss";
5
+ declare const meta: {
6
+ title: string;
7
+ component: typeof Button;
8
+ tags: string[];
9
+ };
10
+ export default meta;
11
+ type Story = StoryObj<typeof meta>;
12
+ export declare const Primary: Story;
13
+ export declare const Back: StoryObj;
14
+ export declare const Forward: StoryObj;
@@ -0,0 +1,9 @@
1
+ import type { StoryObj } from "@storybook/react";
2
+ import "../../scss/globals.scss";
3
+ import "../../scss/components/inline-icon.scss";
4
+ declare const meta: {
5
+ title: string;
6
+ tags: string[];
7
+ };
8
+ export default meta;
9
+ export declare const CheckIcon: StoryObj;
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ interface ButtonProps {
3
+ /** The label of the button */
4
+ children?: string;
5
+ /** The callback function when the button is clicked */
6
+ onClick?: () => void;
7
+ /** Appearance */
8
+ appearance: "primary" | "secondary" | "tertiary";
9
+ }
10
+ interface IconButtonProps {
11
+ /** The label of the button */
12
+ children?: string;
13
+ /** The callback function when the button is clicked */
14
+ onClick?: () => void;
15
+ }
16
+ /** A button with just text */
17
+ export declare function Button({ children, onClick, appearance }: ButtonProps): JSX.Element;
18
+ export declare function BackButton({ children, onClick }: IconButtonProps): JSX.Element;
19
+ export declare function ForwardButton({ children, onClick }: IconButtonProps): JSX.Element;
20
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { SVGProps } from "react";
2
+ declare const SvgArrowBack: (props: SVGProps<SVGSVGElement>) => JSX.Element;
3
+ export default SvgArrowBack;
@@ -0,0 +1,3 @@
1
+ import type { SVGProps } from "react";
2
+ declare const SvgCheck: (props: SVGProps<SVGSVGElement>) => JSX.Element;
3
+ export default SvgCheck;
@@ -0,0 +1,3 @@
1
+ import type { SVGProps } from "react";
2
+ declare const SvgArrowForward: (props: SVGProps<SVGSVGElement>) => JSX.Element;
3
+ export default SvgArrowForward;
@@ -1,2 +1,5 @@
1
1
  export { Tab, ContentTabs, NavigationTabs } from "./components/Tabs";
2
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";
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
+ import React__default from 'react';
2
3
 
3
4
  function getValueFromUrl(key) {
4
5
  const url = new URL(location.href);
@@ -18,8 +19,8 @@ function getValueFromUrl(key) {
18
19
  */
19
20
  function useUrlState(defaultValue = "", key = "", enableUrl = false) {
20
21
  const initialValue = (enableUrl && getValueFromUrl(key)) || defaultValue;
21
- const [value, _setValue] = React.useState(initialValue);
22
- React.useEffect(() => {
22
+ const [value, _setValue] = React__default.useState(initialValue);
23
+ React__default.useEffect(() => {
23
24
  function updateValue() {
24
25
  if (enableUrl) {
25
26
  _setValue(getValueFromUrl(key) || defaultValue);
@@ -77,47 +78,72 @@ function useFocus(element) {
77
78
  * You should use {@link NavigationTabs} or {@link ContentTabs} instead.
78
79
  */
79
80
  function GenericTabs({ classPrefix, children, id, defaultValue, url = "none", }) {
80
- const ref = React.useRef(null);
81
+ const ref = React__default.useRef(null);
81
82
  const [activeTab, setActiveTab] = useUrlState(defaultValue, url === "query" ? id : "", url === "query" || url === "hash");
82
83
  let activeTabIndex = children.findIndex((c) => c.props.id === activeTab);
83
84
  if (activeTabIndex === -1) {
84
85
  activeTabIndex = 0;
85
86
  }
86
87
  useFocus(ref.current?.querySelector(`#${activeTab}-tab`));
87
- return (React.createElement(React.Fragment, null,
88
- React.createElement("div", { ref: ref, className: `${classPrefix}`, id: id },
89
- React.createElement("ul", { className: `${classPrefix}__tablist`, role: "tablist" }, children.map((child, index) => (React.createElement("li", { role: "presentation", className: `${classPrefix}__tab-element` },
90
- 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) => {
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) => {
91
92
  handleKeyDown(event, index, children, setActiveTab);
92
93
  }, onClick: (event) => {
93
94
  event.preventDefault();
94
95
  setActiveTab(child.props.id);
95
96
  } }, child.props.title)))))),
96
- 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)))));
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)))));
97
98
  }
98
99
  function NavigationTabs({ id, children, url = "query", defaultValue, }) {
99
- return (React.createElement(GenericTabs, { id: id, children: children, url: url, defaultValue: defaultValue, classPrefix: "kth-navigation-tabs" }));
100
+ return (React__default.createElement(GenericTabs, { id: id, children: children, url: url, defaultValue: defaultValue, classPrefix: "kth-navigation-tabs" }));
100
101
  }
101
102
  function ContentTabs({ id, children, url = "hash", defaultValue, }) {
102
- return (React.createElement(GenericTabs, { id: id, children: children, url: url, defaultValue: defaultValue, classPrefix: "kth-content-tabs" }));
103
+ return (React__default.createElement(GenericTabs, { id: id, children: children, url: url, defaultValue: defaultValue, classPrefix: "kth-content-tabs" }));
103
104
  }
104
105
  function Tab({ children }) {
105
- return React.createElement(React.Fragment, null, children);
106
+ return React__default.createElement(React__default.Fragment, null, children);
106
107
  }
107
108
 
108
109
  function Select({ name, label, description, value, onChange, children, error, }) {
109
110
  const id = `select-${name}`;
110
- return (React.createElement("div", { className: "kth-select" },
111
- React.createElement("label", { htmlFor: id }, label),
112
- description && React.createElement("p", { id: `${id}-description` }, description),
113
- 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),
114
- error && (React.createElement("p", { className: "kth-select__error", role: "alert" }, error))));
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))));
115
116
  }
116
117
  function OptionGroup({ label, children }) {
117
- return React.createElement("optgroup", { label: label }, children);
118
+ return React__default.createElement("optgroup", { label: label }, children);
118
119
  }
119
120
  function Option({ value, children }) {
120
- return React.createElement("option", { value: value }, children);
121
+ return React__default.createElement("option", { value: value }, children);
121
122
  }
122
123
 
123
- export { ContentTabs, NavigationTabs, Option, OptionGroup, Select, Tab };
124
+ const SvgArrowBack = (props) => (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1.25em", height: "1.25em", viewBox: "0 0 20 20", ...props },
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 };
@@ -0,0 +1,14 @@
1
+ import type { StoryObj } from "@storybook/react";
2
+ import { Button } from "../components/Button";
3
+ import "../../scss/globals.scss";
4
+ import "../../scss/components/button.scss";
5
+ declare const meta: {
6
+ title: string;
7
+ component: typeof Button;
8
+ tags: string[];
9
+ };
10
+ export default meta;
11
+ type Story = StoryObj<typeof meta>;
12
+ export declare const Primary: Story;
13
+ export declare const Back: StoryObj;
14
+ export declare const Forward: StoryObj;
@@ -0,0 +1,9 @@
1
+ import type { StoryObj } from "@storybook/react";
2
+ import "../../scss/globals.scss";
3
+ import "../../scss/components/inline-icon.scss";
4
+ declare const meta: {
5
+ title: string;
6
+ tags: string[];
7
+ };
8
+ export default meta;
9
+ export declare const CheckIcon: StoryObj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kth/style",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "scripts": {
@@ -47,5 +47,5 @@
47
47
  "peerDependencies": {
48
48
  "react": "*"
49
49
  },
50
- "gitHead": "4485935e665dcf7e8734c7142b6c4d913211c77f"
50
+ "gitHead": "01c4ee2c400d90bf6e9fcf61eec4a0a086aac49d"
51
51
  }