@kth/style 0.0.6 → 0.0.8
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/dist/cjs/components/Select.d.ts +6 -1
- package/dist/cjs/index.js +7 -9
- package/dist/cjs/stories/Select.stories.d.ts +2 -1
- package/dist/esm/components/Select.d.ts +6 -1
- package/dist/esm/index.js +7 -9
- package/dist/esm/stories/Select.stories.d.ts +2 -1
- package/package.json +2 -2
- package/scss/components/button.scss +72 -0
- package/scss/components/form.scss +48 -0
- package/scss/components/inline-icon.scss +7 -0
- package/scss/components/select.scss +0 -24
|
@@ -12,6 +12,11 @@ interface SelectProps {
|
|
|
12
12
|
onChange(value: string): void;
|
|
13
13
|
/** Options */
|
|
14
14
|
children: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Error message if the field has errors. `undefined` here means the field
|
|
17
|
+
* contains no error.
|
|
18
|
+
*/
|
|
19
|
+
error?: string;
|
|
15
20
|
}
|
|
16
21
|
interface OptionProps {
|
|
17
22
|
/** The value for the option */
|
|
@@ -23,7 +28,7 @@ interface OptionGroupProps {
|
|
|
23
28
|
label: string;
|
|
24
29
|
children: React.ReactNode;
|
|
25
30
|
}
|
|
26
|
-
export declare function Select({ name, label, description, value, onChange, children, }: SelectProps): JSX.Element;
|
|
31
|
+
export declare function Select({ name, label, description, value, onChange, children, error, }: SelectProps): JSX.Element;
|
|
27
32
|
export declare function OptionGroup({ label, children }: OptionGroupProps): JSX.Element;
|
|
28
33
|
export declare function Option({ value, children }: OptionProps): JSX.Element;
|
|
29
34
|
export {};
|
package/dist/cjs/index.js
CHANGED
|
@@ -107,21 +107,19 @@ function Tab({ children }) {
|
|
|
107
107
|
return React.createElement(React.Fragment, null, children);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
function Select({ name, label, description, value, onChange, children, }) {
|
|
110
|
+
function Select({ name, label, description, value, onChange, children, error, }) {
|
|
112
111
|
const id = `select-${name}`;
|
|
113
|
-
return (React.createElement(
|
|
114
|
-
React.createElement("
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
return (React.createElement("div", { className: "kth-select" },
|
|
113
|
+
React.createElement("label", { htmlFor: id }, label),
|
|
114
|
+
description && React.createElement("p", { id: `${id}-description` }, description),
|
|
115
|
+
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),
|
|
116
|
+
error && (React.createElement("p", { className: "kth-select__error", role: "alert" }, error))));
|
|
118
117
|
}
|
|
119
118
|
function OptionGroup({ label, children }) {
|
|
120
119
|
return React.createElement("optgroup", { label: label }, children);
|
|
121
120
|
}
|
|
122
121
|
function Option({ value, children }) {
|
|
123
|
-
|
|
124
|
-
return (React.createElement("option", { value: value, selected: value === selectedValue }, children));
|
|
122
|
+
return React.createElement("option", { value: value }, children);
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
exports.ContentTabs = ContentTabs;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StoryObj } from "@storybook/react";
|
|
2
2
|
import { Select } from "../components/Select";
|
|
3
3
|
import "../../scss/globals.scss";
|
|
4
|
-
import "../../scss/components/
|
|
4
|
+
import "../../scss/components/form.scss";
|
|
5
5
|
declare const meta: {
|
|
6
6
|
title: string;
|
|
7
7
|
component: typeof Select;
|
|
@@ -11,3 +11,4 @@ export default meta;
|
|
|
11
11
|
type Story = StoryObj<typeof meta>;
|
|
12
12
|
export declare const WithDescriptions: Story;
|
|
13
13
|
export declare const WithoutDescriptions: Story;
|
|
14
|
+
export declare const WithError: Story;
|
|
@@ -12,6 +12,11 @@ interface SelectProps {
|
|
|
12
12
|
onChange(value: string): void;
|
|
13
13
|
/** Options */
|
|
14
14
|
children: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Error message if the field has errors. `undefined` here means the field
|
|
17
|
+
* contains no error.
|
|
18
|
+
*/
|
|
19
|
+
error?: string;
|
|
15
20
|
}
|
|
16
21
|
interface OptionProps {
|
|
17
22
|
/** The value for the option */
|
|
@@ -23,7 +28,7 @@ interface OptionGroupProps {
|
|
|
23
28
|
label: string;
|
|
24
29
|
children: React.ReactNode;
|
|
25
30
|
}
|
|
26
|
-
export declare function Select({ name, label, description, value, onChange, children, }: SelectProps): JSX.Element;
|
|
31
|
+
export declare function Select({ name, label, description, value, onChange, children, error, }: SelectProps): JSX.Element;
|
|
27
32
|
export declare function OptionGroup({ label, children }: OptionGroupProps): JSX.Element;
|
|
28
33
|
export declare function Option({ value, children }: OptionProps): JSX.Element;
|
|
29
34
|
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -105,21 +105,19 @@ function Tab({ children }) {
|
|
|
105
105
|
return React.createElement(React.Fragment, null, children);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
function Select({ name, label, description, value, onChange, children, }) {
|
|
108
|
+
function Select({ name, label, description, value, onChange, children, error, }) {
|
|
110
109
|
const id = `select-${name}`;
|
|
111
|
-
return (React.createElement(
|
|
112
|
-
React.createElement("
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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))));
|
|
116
115
|
}
|
|
117
116
|
function OptionGroup({ label, children }) {
|
|
118
117
|
return React.createElement("optgroup", { label: label }, children);
|
|
119
118
|
}
|
|
120
119
|
function Option({ value, children }) {
|
|
121
|
-
|
|
122
|
-
return (React.createElement("option", { value: value, selected: value === selectedValue }, children));
|
|
120
|
+
return React.createElement("option", { value: value }, children);
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
export { ContentTabs, NavigationTabs, Option, OptionGroup, Select, Tab };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StoryObj } from "@storybook/react";
|
|
2
2
|
import { Select } from "../components/Select";
|
|
3
3
|
import "../../scss/globals.scss";
|
|
4
|
-
import "../../scss/components/
|
|
4
|
+
import "../../scss/components/form.scss";
|
|
5
5
|
declare const meta: {
|
|
6
6
|
title: string;
|
|
7
7
|
component: typeof Select;
|
|
@@ -11,3 +11,4 @@ export default meta;
|
|
|
11
11
|
type Story = StoryObj<typeof meta>;
|
|
12
12
|
export declare const WithDescriptions: Story;
|
|
13
13
|
export declare const WithoutDescriptions: Story;
|
|
14
|
+
export declare const WithError: Story;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kth/style",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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": "
|
|
50
|
+
"gitHead": "4485935e665dcf7e8734c7142b6c4d913211c77f"
|
|
51
51
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
@use "../tokens/" as t;
|
|
2
|
+
|
|
3
|
+
@layer kth-style {
|
|
4
|
+
.kth-button {
|
|
5
|
+
padding-inline: var(--kth-0-clickable-padding-inline);
|
|
6
|
+
border-radius: t.$space-4;
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
gap: t.$space-4;
|
|
9
|
+
align-items: center;
|
|
10
|
+
|
|
11
|
+
&.primary {
|
|
12
|
+
background: t.$color-primary-5;
|
|
13
|
+
color: t.$color-neutral-0;
|
|
14
|
+
border: none;
|
|
15
|
+
padding-block: var(--kth-0-clickable-padding-block);
|
|
16
|
+
font-weight: t.$font-weight-bold;
|
|
17
|
+
|
|
18
|
+
&:hover {
|
|
19
|
+
background: t.$color-primary-6;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.secondary {
|
|
24
|
+
background: transparent;
|
|
25
|
+
color: t.$color-neutral-10;
|
|
26
|
+
border: 1px solid t.$color-neutral-10;
|
|
27
|
+
padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&.tertiary {
|
|
31
|
+
padding-inline: 0;
|
|
32
|
+
background: transparent;
|
|
33
|
+
color: t.$color-primary-5;
|
|
34
|
+
border: none;
|
|
35
|
+
padding-block: calc(var(--kth-0-clickable-padding-block));
|
|
36
|
+
|
|
37
|
+
&:hover {
|
|
38
|
+
text-decoration: underline;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.kth-select,
|
|
44
|
+
.kth-input {
|
|
45
|
+
margin-block: t.$space-24;
|
|
46
|
+
|
|
47
|
+
label {
|
|
48
|
+
display: inline-block;
|
|
49
|
+
font-weight: 600;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
p {
|
|
53
|
+
margin: t.$space-4 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
select {
|
|
57
|
+
margin-top: t.$space-8;
|
|
58
|
+
padding-inline: var(--kth-0-clickable-padding-inline);
|
|
59
|
+
padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
|
|
60
|
+
border-radius: t.$space-4;
|
|
61
|
+
border: 1px solid t.$color-neutral-10;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
input {
|
|
65
|
+
margin-top: t.$space-8;
|
|
66
|
+
padding-inline: var(--kth-0-clickable-padding-inline);
|
|
67
|
+
padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
|
|
68
|
+
border-radius: t.$space-4;
|
|
69
|
+
border: 1px solid t.$color-neutral-10;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
@use "../tokens/" as t;
|
|
2
|
+
|
|
3
|
+
@layer kth-style {
|
|
4
|
+
.kth-select,
|
|
5
|
+
.kth-input {
|
|
6
|
+
margin-block: t.$space-24;
|
|
7
|
+
|
|
8
|
+
label {
|
|
9
|
+
display: block;
|
|
10
|
+
font-weight: 600;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
p {
|
|
14
|
+
margin: t.$space-4 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
select {
|
|
18
|
+
margin-top: t.$space-8;
|
|
19
|
+
padding-inline: var(--kth-0-clickable-padding-inline);
|
|
20
|
+
padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
|
|
21
|
+
border-radius: t.$space-4;
|
|
22
|
+
border: 1px solid t.$color-neutral-10;
|
|
23
|
+
|
|
24
|
+
&[aria-invalid="true"] {
|
|
25
|
+
color: t.$color-danger-5;
|
|
26
|
+
border-color: t.$color-danger-5;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
input {
|
|
31
|
+
margin-top: t.$space-8;
|
|
32
|
+
padding-inline: var(--kth-0-clickable-padding-inline);
|
|
33
|
+
padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
|
|
34
|
+
border-radius: t.$space-4;
|
|
35
|
+
border: 1px solid t.$color-neutral-10;
|
|
36
|
+
|
|
37
|
+
&[aria-invalid="true"] {
|
|
38
|
+
color: t.$color-danger-5;
|
|
39
|
+
border-color: t.$color-danger-5;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&__error {
|
|
44
|
+
margin-top: t.$space-8;
|
|
45
|
+
color: t.$color-danger-5;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
@use "../tokens/" as t;
|
|
2
|
-
|
|
3
|
-
@layer kth-style {
|
|
4
|
-
.kth-select {
|
|
5
|
-
margin-block: t.$space-24;
|
|
6
|
-
|
|
7
|
-
label {
|
|
8
|
-
display: inline-block;
|
|
9
|
-
font-weight: 600;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
p {
|
|
13
|
-
margin: t.$space-4 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
select {
|
|
17
|
-
margin-top: t.$space-8;
|
|
18
|
-
padding-inline: var(--kth-0-clickable-padding-inline);
|
|
19
|
-
padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
|
|
20
|
-
border-radius: t.$space-4;
|
|
21
|
-
border-block: 1px solid t.$color-neutral-10;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|