@vygruppen/spor-react 12.5.6 → 12.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vygruppen/spor-react",
3
- "version": "12.5.6",
3
+ "version": "12.6.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./dist/index.d.ts",
@@ -70,7 +70,7 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
70
70
  <HStack gap="1" alignItems="flex-start">
71
71
  {showIndicator && (
72
72
  <ChakraAlert.Indicator asChild>
73
- <AlertIcon variant={props.variant} customIcon={icon} />
73
+ <AlertIcon variant={props.variant ?? "info"} customIcon={icon} />
74
74
  </ChakraAlert.Indicator>
75
75
  )}
76
76
  {title && (
@@ -9,8 +9,6 @@ import {
9
9
  } from "react-aria";
10
10
  import { useCalendarState } from "react-stately";
11
11
 
12
- import { datePickerSlotRecipe } from "@/theme/slot-recipes/datepicker";
13
-
14
12
  import { createTexts, useTranslation } from "../i18n";
15
13
  import { CalendarGrid } from "./CalendarGrid";
16
14
  import { CalendarHeader } from "./CalendarHeader";
@@ -33,9 +31,9 @@ export function Calendar({
33
31
  locale,
34
32
  createCalendar,
35
33
  });
34
+
36
35
  const recipe = useSlotRecipe({
37
36
  key: "datePicker",
38
- recipe: datePickerSlotRecipe,
39
37
  });
40
38
  const styles = recipe({ variant });
41
39
  const { calendarProps } = useCalendar(props, state);
@@ -11,7 +11,6 @@ import { PropsWithChildren, useEffect, useRef } from "react";
11
11
  import { useCalendarCell } from "react-aria";
12
12
  import { CalendarState, RangeCalendarState } from "react-stately";
13
13
 
14
- import { datePickerSlotRecipe } from "../theme/slot-recipes/datepicker";
15
14
  import { DatePickerVariantProps } from "./DatePicker";
16
15
  import { CalendarVariants } from "./types";
17
16
 
@@ -38,9 +37,9 @@ export function CalendarCell({
38
37
  } = useCalendarCell({ date }, state, ref);
39
38
 
40
39
  const isOutsideMonth = !isSameMonth(currentMonth, date);
40
+
41
41
  const recipe = useSlotRecipe({
42
42
  key: "datePicker",
43
- recipe: datePickerSlotRecipe,
44
43
  });
45
44
  const styles = recipe({ variant });
46
45
 
@@ -6,7 +6,6 @@ import { AriaCalendarGridProps, useCalendarGrid } from "react-aria";
6
6
  import { CalendarState, RangeCalendarState } from "react-stately";
7
7
 
8
8
  import { Language, useTranslation } from "../i18n";
9
- import { datePickerSlotRecipe } from "../theme/slot-recipes/datepicker";
10
9
  import { Text } from "../typography";
11
10
  import { CalendarCell } from "./CalendarCell";
12
11
  import { CalendarVariants } from "./types";
@@ -46,9 +45,9 @@ export function CalendarGrid({
46
45
  const weeksInMonthRange = Array.from({ length: weeksInMonth })
47
46
  .fill(0)
48
47
  .map((_, i) => i);
48
+
49
49
  const recipe = useSlotRecipe({
50
50
  key: "datePicker",
51
- recipe: datePickerSlotRecipe,
52
51
  });
53
52
  const styles = recipe({ variant });
54
53
 
@@ -11,7 +11,6 @@ import {
11
11
  IconButton,
12
12
  useTranslation,
13
13
  } from "..";
14
- import { datePickerSlotRecipe } from "../theme/slot-recipes/datepicker";
15
14
  import { CalendarVariants } from "./types";
16
15
 
17
16
  type CalendarTriggerButtonProps = AriaButtonProps<"button"> &
@@ -26,9 +25,9 @@ export const CalendarTriggerButton = forwardRef<
26
25
  CalendarTriggerButtonProps
27
26
  >(({ variant, disabled, ariaLabelledby, ...buttonProps }, ref) => {
28
27
  const { t } = useTranslation();
28
+
29
29
  const recipe = useSlotRecipe({
30
30
  key: "datePicker",
31
- recipe: datePickerSlotRecipe,
32
31
  });
33
32
  const styles = recipe({ variant });
34
33
 
@@ -7,7 +7,6 @@ import { AriaDateFieldProps, useDateField } from "react-aria";
7
7
  import { DateSegment, useDateFieldState } from "react-stately";
8
8
 
9
9
  import { createTexts, useTranslation } from "../i18n";
10
- import { datePickerSlotRecipe } from "../theme/slot-recipes/datepicker";
11
10
  import { DatePickerVariantProps } from "./DatePicker";
12
11
  import { DateTimeSegment } from "./DateTimeSegment";
13
12
  import { useCurrentLocale } from "./utils";
@@ -33,9 +32,9 @@ type DateFieldProps = AriaDateFieldProps<DateValue> &
33
32
  export const DateField = forwardRef<HTMLDivElement, DateFieldProps>(
34
33
  ({ labelId, ...props }, externalRef) => {
35
34
  const locale = useCurrentLocale();
35
+
36
36
  const recipe = useSlotRecipe({
37
37
  key: "datePicker",
38
- recipe: datePickerSlotRecipe,
39
38
  });
40
39
  const styles = recipe({});
41
40
  const state = useDateFieldState({
@@ -93,8 +93,8 @@ export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
93
93
 
94
94
  const recipe = useSlotRecipe({
95
95
  key: "datePicker",
96
- recipe: datePickerSlotRecipe,
97
96
  });
97
+
98
98
  const styles = recipe({ variant });
99
99
  const locale = useCurrentLocale();
100
100
 
@@ -20,7 +20,6 @@ import {
20
20
  import { useDateRangePickerState } from "react-stately";
21
21
 
22
22
  import { Field, FieldBaseProps } from "../input/Field";
23
- import { datePickerSlotRecipe } from "../theme/slot-recipes/datepicker";
24
23
  import { CalendarTriggerButton } from "./CalendarTriggerButton";
25
24
  import { DateField } from "./DateField";
26
25
  import { DatePickerVariantProps } from "./DatePicker";
@@ -94,7 +93,6 @@ type DateRangePickerProps = Omit<
94
93
 
95
94
  const recipe = useSlotRecipe({
96
95
  key: "datePicker",
97
- recipe: datePickerSlotRecipe,
98
96
  });
99
97
  const styles = recipe({ variant });
100
98
  const locale = useCurrentLocale();
@@ -5,7 +5,6 @@ import { useDateSegment } from "react-aria";
5
5
  import { DateFieldState, DateSegment } from "react-stately";
6
6
 
7
7
  import { DatePickerVariantProps } from "..";
8
- import { datePickerSlotRecipe } from "../theme/slot-recipes/datepicker";
9
8
 
10
9
  type DateTimeSegmentProps = PropsWithChildren<DatePickerVariantProps> & {
11
10
  segment: DateSegment;
@@ -33,8 +32,8 @@ export const DateTimeSegment = forwardRef<HTMLDivElement, DateTimeSegmentProps>(
33
32
 
34
33
  const recipe = useSlotRecipe({
35
34
  key: "datePicker",
36
- recipe: datePickerSlotRecipe,
37
35
  });
36
+
38
37
  const styles = recipe({
39
38
  isPlaceholder: segment.isPlaceholder,
40
39
  isEditable: segment.isEditable,
@@ -8,8 +8,6 @@ import {
8
8
  } from "react-aria";
9
9
  import { useRangeCalendarState } from "react-stately";
10
10
 
11
- import { datePickerSlotRecipe } from "@/theme/slot-recipes/datepicker";
12
-
13
11
  import { CalendarGrid } from "./CalendarGrid";
14
12
  import { CalendarHeader } from "./CalendarHeader";
15
13
  import { CalendarVariants } from "./types";
@@ -26,9 +24,9 @@ export function RangeCalendar(props: RangeCalendarProps) {
26
24
  locale,
27
25
  createCalendar,
28
26
  });
27
+
29
28
  const recipe = useSlotRecipe({
30
29
  key: "datePicker",
31
- recipe: datePickerSlotRecipe,
32
30
  });
33
31
  const styles = recipe({});
34
32
  const ref = useRef(null);
@@ -7,7 +7,6 @@ import {
7
7
  } from "@chakra-ui/react";
8
8
  import { forwardRef, PropsWithChildren } from "react";
9
9
 
10
- import { datePickerSlotRecipe } from "../theme/slot-recipes/datepicker";
11
10
  import { DatePickerVariantProps } from "./DatePicker";
12
11
  import { CalendarVariants } from "./types";
13
12
 
@@ -27,7 +26,6 @@ export const StyledField = forwardRef<HTMLDivElement, StyledFieldProps>(
27
26
 
28
27
  const recipe = useSlotRecipe({
29
28
  key: "datePicker",
30
- recipe: datePickerSlotRecipe,
31
29
  });
32
30
  const styles = recipe({ variant });
33
31
 
@@ -1,4 +1,5 @@
1
1
  export * from "./DatePicker";
2
2
  export * from "./DateRangePicker";
3
+ export * from "./RangeCalendar";
3
4
  export * from "./TimePicker";
4
5
  export { Time } from "@internationalized/date";
@@ -55,7 +55,7 @@ export const NativeSelect = React.forwardRef<
55
55
  ...rest
56
56
  } = props;
57
57
 
58
- const recipe = useSlotRecipe({ recipe: nativeSelectSlotRecipe });
58
+ const recipe = useSlotRecipe({ key: "nativeSelect" });
59
59
  const styles = recipe({ variant });
60
60
 
61
61
  return (
@@ -88,7 +88,7 @@ export const NumericStepper = React.forwardRef<
88
88
 
89
89
  const addButtonRef = useRef<HTMLButtonElement>(null);
90
90
  const { t } = useTranslation();
91
- const recipe = useSlotRecipe({ recipe: numericStepperRecipe });
91
+ const recipe = useSlotRecipe({ key: "numericStepper" });
92
92
  const styles = recipe();
93
93
  const [value, onChange] = useControllableState<number>({
94
94
  value: valueProp,
@@ -209,7 +209,7 @@ const VerySmallButton = React.forwardRef<
209
209
  HTMLButtonElement,
210
210
  VerySmallButtonProps
211
211
  >((props, ref) => {
212
- const recipe = useSlotRecipe({ recipe: numericStepperRecipe });
212
+ const recipe = useSlotRecipe({ key: "numericStepper" });
213
213
  const styles = recipe({ colorPalette: "default" });
214
214
  return (
215
215
  <IconButton
@@ -26,7 +26,7 @@ export const Separator = forwardRef<HTMLDivElement, SeparatorProps>(
26
26
  orientation = "horizontal",
27
27
  } = props;
28
28
 
29
- const recipe = useRecipe({ recipe: separatorRecipe });
29
+ const recipe = useRecipe({ key: "seperator" });
30
30
  const styles = recipe({ size, variant, orientation });
31
31
  return <ChakraSeparator css={styles} {...props} ref={ref} />;
32
32
  },
@@ -26,7 +26,7 @@ export const SkeletonCircle = React.forwardRef<
26
26
  HTMLDivElement,
27
27
  SkeletonCircleProps
28
28
  >(function SkeletonCircle(props, ref) {
29
- const recipe = useRecipe({ recipe: skeletonRecipe });
29
+ const recipe = useRecipe({ key: "skeleton" });
30
30
 
31
31
  const [recipeProps, restProps] = recipe.splitVariantProps({
32
32
  loading: true,
@@ -50,7 +50,7 @@ export type SkeletonTextProps = ChakraSkeletonProps &
50
50
 
51
51
  export const SkeletonText = forwardRef<HTMLDivElement, SkeletonTextProps>(
52
52
  function SkeletonText(props, ref) {
53
- const recipe = useRecipe({ recipe: skeletonRecipe });
53
+ const recipe = useRecipe({ key: "skeleton" });
54
54
  const [recipeProps, restProps] = recipe.splitVariantProps({
55
55
  loading: true,
56
56
  variant: "pulse",
@@ -78,7 +78,7 @@ export type SkeletonProps = ChakraSkeletonProps & SkeletonVariantProps;
78
78
 
79
79
  export const Skeleton = forwardRef<HTMLDivElement, SkeletonTextProps>(
80
80
  function SkeletonText(props, ref) {
81
- const recipe = useRecipe({ recipe: skeletonRecipe });
81
+ const recipe = useRecipe({ key: "skeleton" });
82
82
  const [recipeProps, restProps] = recipe.splitVariantProps({
83
83
  loading: true,
84
84
  variant: "pulse",
@@ -35,7 +35,7 @@ export type TableProps = Exclude<ChakraTableProps, "variant" | "colorPalette"> &
35
35
  export const Table = forwardRef<HTMLTableElement, TableProps>((props, ref) => {
36
36
  const { variant = "ghost", size, colorPalette = "green", children } = props;
37
37
 
38
- const recipe = useSlotRecipe({ recipe: tableSlotRecipe });
38
+ const recipe = useSlotRecipe({ key: "table" });
39
39
  const styles = recipe({ variant, size });
40
40
  return (
41
41
  <ChakraTable.Root
@@ -13,6 +13,31 @@ export type TextProps = Omit<ChakraTextProps, "textStyle"> & {
13
13
  variant?: ChakraTextProps["textStyle"];
14
14
  };
15
15
 
16
+ /**
17
+ * Determines the correct props to pass to ChakraText,
18
+ * based on the user's intent and sensible defaults.
19
+ */
20
+ function resolveTextProps({
21
+ variant,
22
+ fontSize,
23
+ lineHeight,
24
+ }: Pick<TextProps, "variant" | "fontSize" | "lineHeight">) {
25
+ // If user provides a variant, use it (overrides fontSize/lineHeight)
26
+ if (variant) return { textStyle: variant };
27
+
28
+ // If neither fontSize nor lineHeight is provided, default to "sm"
29
+ if (!fontSize && !lineHeight) return { textStyle: "sm" };
30
+
31
+ // If only lineHeight is provided, default fontSize to "sm"
32
+ if (lineHeight && !fontSize) return { lineHeight, fontSize: "sm" };
33
+
34
+ // If only fontSize is provided, use it and let Chakra handle lineHeight
35
+ if (fontSize && !lineHeight) return { fontSize };
36
+
37
+ // If both are provided, use both
38
+ return { fontSize, lineHeight };
39
+ }
40
+
16
41
  /**
17
42
  * A paragraph of text.
18
43
  *
@@ -20,10 +45,11 @@ export type TextProps = Omit<ChakraTextProps, "textStyle"> & {
20
45
  * <Text>Welcome to this paragraph of text.</Text>
21
46
  * ```
22
47
  */
23
-
24
48
  export const Text = forwardRef<HTMLParagraphElement, TextProps>(
25
49
  function Text(props, ref) {
26
- const { variant = "sm", ...rest } = props;
27
- return <ChakraText {...rest} textStyle={variant} ref={ref} />;
50
+ const { variant, lineHeight, fontSize, ...rest } = props;
51
+ const resolvedProps = resolveTextProps({ variant, fontSize, lineHeight });
52
+
53
+ return <ChakraText {...resolvedProps} {...rest} ref={ref} />;
28
54
  },
29
55
  );