@kth/style 0.0.7 → 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.
@@ -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,12 +107,13 @@ function Tab({ children }) {
107
107
  return React.createElement(React.Fragment, null, children);
108
108
  }
109
109
 
110
- function Select({ name, label, description, value, onChange, children, }) {
110
+ function Select({ name, label, description, value, onChange, children, error, }) {
111
111
  const id = `select-${name}`;
112
112
  return (React.createElement("div", { className: "kth-select" },
113
113
  React.createElement("label", { htmlFor: id }, label),
114
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) }, children)));
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))));
116
117
  }
117
118
  function OptionGroup({ label, children }) {
118
119
  return React.createElement("optgroup", { label: label }, children);
@@ -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/select.scss";
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,12 +105,13 @@ function Tab({ children }) {
105
105
  return React.createElement(React.Fragment, null, children);
106
106
  }
107
107
 
108
- function Select({ name, label, description, value, onChange, children, }) {
108
+ function Select({ name, label, description, value, onChange, children, error, }) {
109
109
  const id = `select-${name}`;
110
110
  return (React.createElement("div", { className: "kth-select" },
111
111
  React.createElement("label", { htmlFor: id }, label),
112
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) }, children)));
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))));
114
115
  }
115
116
  function OptionGroup({ label, children }) {
116
117
  return React.createElement("optgroup", { label: label }, children);
@@ -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/select.scss";
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.7",
3
+ "version": "0.0.8",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "scripts": {
@@ -46,5 +46,6 @@
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": "*"
49
- }
49
+ },
50
+ "gitHead": "4485935e665dcf7e8734c7142b6c4d913211c77f"
50
51
  }
@@ -3,19 +3,39 @@
3
3
  @layer kth-style {
4
4
  .kth-button {
5
5
  padding-inline: var(--kth-0-clickable-padding-inline);
6
- padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
7
- border: 1px solid t.$color-neutral-10;
8
6
  border-radius: t.$space-4;
7
+ display: inline-flex;
8
+ gap: t.$space-4;
9
+ align-items: center;
9
10
 
10
11
  &.primary {
11
- font-weight: t.$font-weight-bold;
12
12
  background: t.$color-primary-5;
13
- border-color: t.$color-primary-5;
14
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;
15
17
 
16
18
  &:hover {
17
19
  background: t.$color-primary-6;
18
- border-color: 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;
19
39
  }
20
40
  }
21
41
  }
@@ -6,7 +6,7 @@
6
6
  margin-block: t.$space-24;
7
7
 
8
8
  label {
9
- display: inline-block;
9
+ display: block;
10
10
  font-weight: 600;
11
11
  }
12
12
 
@@ -20,6 +20,11 @@
20
20
  padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
21
21
  border-radius: t.$space-4;
22
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
+ }
23
28
  }
24
29
 
25
30
  input {
@@ -28,6 +33,16 @@
28
33
  padding-block: calc(var(--kth-0-clickable-padding-block) - 1px);
29
34
  border-radius: t.$space-4;
30
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;
31
46
  }
32
47
  }
33
48
  }
@@ -0,0 +1,7 @@
1
+ @use "../tokens/" as t;
2
+ @layer kth-style {
3
+ .kth-inline-icon {
4
+ display: inline-block;
5
+ vertical-align: -12.5%;
6
+ }
7
+ }