@vygruppen/spor-react 6.0.0 → 6.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.
@@ -3,10 +3,23 @@ import React from "react";
3
3
  import { getCorrectIcon } from "./icons";
4
4
  import { TagProps } from "./types";
5
5
 
6
- export type LineIconProps = BoxProps & {
7
- variant: TagProps["variant"];
8
- size: TagProps["size"];
6
+ type DefaultVariants = Exclude<TagProps["variant"], "custom">;
7
+
8
+ type DefaultVariantProps = {
9
+ variant: DefaultVariants;
10
+ };
11
+ type CustomVariantProps = {
12
+ variant: "custom";
13
+ customIconVariant: DefaultVariants;
14
+ foregroundColor: string;
15
+ backgroundColor: string;
9
16
  };
17
+ type VariantProps = DefaultVariantProps | CustomVariantProps;
18
+
19
+ export type LineIconProps = Exclude<BoxProps, "variant"> &
20
+ VariantProps & {
21
+ size: TagProps["size"];
22
+ };
10
23
 
11
24
  /**
12
25
  * A line icon component.
@@ -23,6 +36,18 @@ export type LineIconProps = BoxProps & {
23
36
  * <LineIcon variant="subway" size="lg" />
24
37
  * ```
25
38
  *
39
+ * If you require some one-off colors, but still want to use the line tag component,
40
+ * you can do so like this:
41
+ *
42
+ * ```tsx
43
+ * <LineIcon
44
+ * variant="custom"
45
+ * customIconVariant="ferry"
46
+ * foregroundColor="#b4da55"
47
+ * backgroundColor="#c0ffee"
48
+ * />
49
+ * ```
50
+ *
26
51
  * @see https://spor.vy.no/components/line-tags
27
52
  */
28
53
  export const LineIcon = ({
@@ -31,8 +56,16 @@ export const LineIcon = ({
31
56
  sx,
32
57
  ...rest
33
58
  }: LineIconProps) => {
34
- const styles = useMultiStyleConfig("LineIcon", { variant, size });
35
- const Icon: any = getCorrectIcon({ variant, size });
59
+ const styles = useMultiStyleConfig("LineIcon", { variant, size, ...rest });
60
+ const Icon: any = getCorrectIcon({
61
+ variant:
62
+ variant === "custom" && "customIconVariant" in rest
63
+ ? rest.customIconVariant
64
+ : variant === "custom"
65
+ ? "local-train"
66
+ : variant,
67
+ size,
68
+ });
36
69
  if (!Icon) {
37
70
  return null;
38
71
  }
@@ -58,6 +58,19 @@ export type TravelTagProps = TagProps &
58
58
  * />
59
59
  * ```
60
60
  *
61
+ * If required, you can also override the colors and icons in these travel tags:
62
+ *
63
+ * ```tsx
64
+ * <TravelTag
65
+ * variant="custom"
66
+ * customIconVariant="ferry"
67
+ * foregroundColor="#b4da55"
68
+ * backgroundColor="#c0ffee"
69
+ * title="3"
70
+ * description="Ringen"
71
+ * />
72
+ * ```
73
+ *
61
74
  * @see https://spor.vy.no/components/line-tags
62
75
  */
63
76
  export const TravelTag = forwardRef<TravelTagProps, As>(
@@ -77,13 +90,20 @@ export const TravelTag = forwardRef<TravelTagProps, As>(
77
90
  variant,
78
91
  size,
79
92
  deviationLevel,
93
+ foregroundColor: variant === "custom" ? rest.foregroundColor : undefined,
94
+ backgroundColor: variant === "custom" ? rest.backgroundColor : undefined,
80
95
  });
81
96
 
82
97
  const DeviationLevelIcon = getDeviationLevelIcon({ deviationLevel, size });
83
98
 
84
99
  return (
85
100
  <Box sx={styles.container} aria-disabled={isDisabled} ref={ref} {...rest}>
86
- <LineIcon variant={variant} size={size} sx={styles.iconContainer} />
101
+ <LineIcon
102
+ variant={variant}
103
+ size={size}
104
+ sx={styles.iconContainer}
105
+ {...(rest as any)}
106
+ />
87
107
  <Box sx={styles.textContainer}>
88
108
  {title && (
89
109
  <Box as="span" sx={styles.title}>
@@ -16,9 +16,24 @@ export type Size = "sm" | "md" | "lg";
16
16
 
17
17
  export type TagType = "info" | "travel";
18
18
 
19
- export type TagProps = {
20
- variant: Variant;
19
+ export type TagProps = VariantProps & {
21
20
  size: Size;
22
21
  title: string;
23
22
  description?: string;
24
23
  };
24
+
25
+ type DefaultVariantProps = {
26
+ variant: Variant;
27
+ };
28
+ type CustomVariantProps = {
29
+ variant: "custom";
30
+ /** When variant="custom", the foreground color of the tag */
31
+ foregroundColor: string;
32
+ /** When variant="custom", the background color of the tag */
33
+ backgroundColor: string;
34
+ /** When variant="custom", this is the icon you want to display.
35
+ * It should be one of the other variants
36
+ */
37
+ customIconVariant: Variant;
38
+ };
39
+ type VariantProps = DefaultVariantProps | CustomVariantProps;
@@ -2,13 +2,11 @@ import { defineStyleConfig } from "@chakra-ui/react";
2
2
  import { mode } from "@chakra-ui/theme-tools";
3
3
  import { colors } from "../foundations";
4
4
  import { getBoxShadowString } from "../utils/box-shadow-utils";
5
- import { focusVisible } from "../utils/focus-utils";
6
5
 
7
6
  const config = defineStyleConfig({
8
7
  baseStyle: {
9
8
  border: 0,
10
9
  borderRadius: "xl",
11
- fontWeight: "bold",
12
10
  transitionProperty: "common",
13
11
  transitionDuration: "normal",
14
12
  textWrap: "wrap",
@@ -36,18 +34,15 @@ const config = defineStyleConfig({
36
34
  // hardcoded background color as alpha-"hack" below is not feasible for dark mode with solid background color
37
35
  backgroundColor: mode("pine", "coralGreen")(props),
38
36
  color: mode("white", "darkTeal")(props),
39
- ...focusVisible({
40
- focus: {
41
- boxShadow: `inset 0 0 0 2px ${mode(
42
- colors.greenHaze,
43
- colors.azure,
44
- )(props)}, inset 0 0 0 4px ${mode(
45
- colors.white,
46
- colors.darkGrey,
47
- )(props)}`,
48
- },
49
- notFocus: { boxShadow: "none" },
50
- }),
37
+ _focusVisible: {
38
+ boxShadow: `inset 0 0 0 2px ${mode(
39
+ colors.greenHaze,
40
+ colors.azure,
41
+ )(props)}, inset 0 0 0 4px ${mode(
42
+ colors.white,
43
+ colors.darkGrey,
44
+ )(props)}`,
45
+ },
51
46
  _hover: {
52
47
  backgroundColor: mode("darkTeal", "blueGreen")(props),
53
48
  },
@@ -58,34 +53,29 @@ const config = defineStyleConfig({
58
53
  secondary: (props) => ({
59
54
  // FIXME: Update to use global defined background color for darkMode whenever it is available instead of alpha
60
55
  backgroundColor: mode("seaMist", "primaryGreen")(props),
61
- color: mode("darkTeal", "white")(props),
56
+ color: mode("darkTeal", "seaMist")(props),
62
57
  // order is important here for now while we do not have global defined background color for darkMode
63
58
  _hover: {
64
59
  backgroundColor: mode("coralGreen", "greenHaze")(props),
65
60
  },
66
- ...focusVisible({
67
- focus: {
61
+ _focusVisible: {
62
+ boxShadow: `inset 0 0 0 2px ${mode(
63
+ colors.greenHaze,
64
+ colors.primaryGreen,
65
+ )(props)}, inset 0 0 0 4px ${mode(
66
+ colors.white,
67
+ colors.darkTeal,
68
+ )(props)}`,
69
+ _hover: {
68
70
  boxShadow: `inset 0 0 0 2px ${mode(
69
71
  colors.greenHaze,
70
- colors.primaryGreen,
72
+ colors.azure,
71
73
  )(props)}, inset 0 0 0 4px ${mode(
72
74
  colors.white,
73
- colors.darkTeal,
75
+ colors.blackAlpha[500],
74
76
  )(props)}`,
75
- _hover: {
76
- boxShadow: `inset 0 0 0 2px ${mode(
77
- colors.greenHaze,
78
- colors.azure,
79
- )(props)}, inset 0 0 0 4px ${mode(
80
- colors.white,
81
- colors.blackAlpha[500],
82
- )(props)}`,
83
- },
84
77
  },
85
- notFocus: {
86
- boxShadow: "none",
87
- },
88
- }),
78
+ },
89
79
  _active: {
90
80
  backgroundColor: mode("mint", "darkTeal")(props),
91
81
  boxShadow: `inset 0 0 0 2px ${mode(
@@ -109,25 +99,16 @@ const config = defineStyleConfig({
109
99
  tertiary: (props) => ({
110
100
  backgroundColor: "transparent",
111
101
  color: mode("darkGrey", "white")(props),
112
- fontWeight: "normal",
113
102
  boxShadow: `inset 0 0 0 1px ${mode(
114
103
  colors.blackAlpha[400],
115
104
  colors.whiteAlpha[400],
116
105
  )(props)}`,
117
- ...focusVisible({
118
- focus: {
119
- boxShadow: getBoxShadowString({
120
- borderWidth: 2,
121
- borderColor: "azure",
122
- }),
123
- },
124
- notFocus: {
125
- boxShadow: `inset 0 0 0 1px ${mode(
126
- colors.blackAlpha[400],
127
- colors.whiteAlpha[400],
128
- )(props)}`,
129
- },
130
- }),
106
+ _focusVisible: {
107
+ boxShadow: getBoxShadowString({
108
+ borderWidth: 2,
109
+ borderColor: "azure",
110
+ }),
111
+ },
131
112
  _hover: {
132
113
  boxShadow: `inset 0 0 0 2px currentColor`,
133
114
  },
@@ -142,18 +123,12 @@ const config = defineStyleConfig({
142
123
  ghost: (props) => ({
143
124
  backgroundColor: "transparent",
144
125
  color: mode("darkGrey", "white")(props),
145
- fontWeight: "normal",
146
- ...focusVisible({
147
- focus: {
148
- boxShadow: getBoxShadowString({
149
- borderColor: mode("greenHaze", "azure")(props),
150
- borderWidth: 2,
151
- }),
152
- },
153
- notFocus: {
154
- outline: "none",
155
- },
156
- }),
126
+ _focusVisible: {
127
+ boxShadow: getBoxShadowString({
128
+ borderColor: mode("greenHaze", "azure")(props),
129
+ borderWidth: 2,
130
+ }),
131
+ },
157
132
  _hover: {
158
133
  backgroundColor: mode("seaMist", "whiteAlpha.200")(props),
159
134
  _disabled: {
@@ -181,26 +156,20 @@ const config = defineStyleConfig({
181
156
  borderWidth: 2,
182
157
  }),
183
158
  },
184
- ...focusVisible({
185
- focus: {
159
+ _focusVisible: {
160
+ boxShadow: getBoxShadowString({
161
+ borderColor: mode("greenHaze", "azure")(props),
162
+ borderWidth: 2,
163
+ baseShadow: "sm",
164
+ }),
165
+ _hover: {
186
166
  boxShadow: getBoxShadowString({
187
167
  borderColor: mode("greenHaze", "azure")(props),
188
168
  borderWidth: 2,
189
- baseShadow: "sm",
169
+ baseShadow: "md",
190
170
  }),
191
- _hover: {
192
- boxShadow: getBoxShadowString({
193
- borderColor: mode("greenHaze", "azure")(props),
194
- borderWidth: 2,
195
- baseShadow: "md",
196
- }),
197
- },
198
171
  },
199
- notFocus: {
200
- outline: "none",
201
- boxShadow: "sm",
202
- },
203
- }),
172
+ },
204
173
  }),
205
174
  },
206
175
  sizes: {
@@ -208,22 +177,26 @@ const config = defineStyleConfig({
208
177
  minHeight: 8,
209
178
  minWidth: 8,
210
179
  fontSize: "18px",
180
+ fontWeight: "bold",
211
181
  },
212
182
  md: {
213
183
  minHeight: 7,
214
184
  minWidth: 7,
215
185
  fontSize: "18px",
186
+ fontWeight: "bold",
216
187
  },
217
188
  sm: {
218
189
  minHeight: 6,
219
190
  minWidth: 6,
220
191
  fontSize: "16px",
192
+ fontWeight: "normal",
221
193
  },
222
194
  xs: {
223
195
  minHeight: 5,
224
196
  minWidth: 5,
225
197
  fontSize: "16px",
226
198
  paddingX: 2,
199
+ fontWeight: "normal",
227
200
  },
228
201
  },
229
202
  defaultProps: {
@@ -34,6 +34,7 @@ const config = helpers.defineMultiStyleConfig({
34
34
  boxShadow: "md",
35
35
  padding: 3,
36
36
  color: mode("darkGrey", "white")(props),
37
+ ...floatingBackground("default", props),
37
38
  },
38
39
  }),
39
40
  variants: {
@@ -92,6 +92,11 @@ const config = helpers.defineMultiStyleConfig({
92
92
  },
93
93
  },
94
94
  }),
95
+ custom: (props) => ({
96
+ iconContainer: {
97
+ backgroundColor: props.backgroundColor,
98
+ },
99
+ }),
95
100
  },
96
101
  sizes: {
97
102
  sm: {
@@ -172,6 +172,11 @@ const config = helpers.defineMultiStyleConfig({
172
172
  display: "none",
173
173
  },
174
174
  }),
175
+ custom: (props) => ({
176
+ container: {
177
+ backgroundColor: props.foregroundColor,
178
+ },
179
+ }),
175
180
  },
176
181
  sizes: {
177
182
  sm: {