@mbao01/common 0.0.31 → 0.0.33

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.
@@ -1,2 +1,2 @@
1
1
  import { type DatePickerProps } from "./types";
2
- export declare const DatePicker: ({ name, size, wide, label, outline, variant, disabled, defaultDate, children, getDateValue, getDateLabel, ...props }: DatePickerProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const DatePicker: ({ name, size, wide, label, outline, variant, disabled, defaultDate, children, getDateValue, getDateLabel, triggerClassName, ...props }: DatePickerProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import { type DateRangePickerProps } from "./types";
2
- export declare const DateRangePicker: ({ name, size, wide, label, outline, variant, disabled, defaultRange, getRangeValue, getRangeLabel, ...props }: DateRangePickerProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const DateRangePicker: ({ name, size, wide, label, outline, variant, disabled, defaultRange, getRangeValue, getRangeLabel, triggerClassName, ...props }: DateRangePickerProps) => import("react/jsx-runtime").JSX.Element;
@@ -3,8 +3,9 @@ import { DateRange, DayPickerMultipleProps, DayPickerRangeProps, DayPickerSingle
3
3
  import { ButtonProps } from "../Button/types";
4
4
  type BaseDatePickerProps = Pick<ButtonProps, "variant" | "outline" | "wide" | "size" | "name" | "disabled"> & {
5
5
  label?: string;
6
+ triggerClassName?: string;
6
7
  };
7
- export type DatePickerProps = BaseDatePickerProps & Omit<DayPickerSingleProps, "mode" | "selected" | "onSelect"> & {
8
+ export type DatePickerProps = BaseDatePickerProps & Omit<DayPickerSingleProps, "mode"> & {
8
9
  children?: ({ date, setDate, }: {
9
10
  date: Date | undefined;
10
11
  setDate: React.Dispatch<React.SetStateAction<Date | undefined>>;
@@ -13,7 +14,7 @@ export type DatePickerProps = BaseDatePickerProps & Omit<DayPickerSingleProps, "
13
14
  getDateLabel?: (date: Date | undefined) => string | undefined;
14
15
  getDateValue?: (date: Date | undefined) => string | undefined;
15
16
  };
16
- export type DateRangePickerProps = BaseDatePickerProps & Omit<DayPickerRangeProps, "mode" | "selected" | "onSelect"> & {
17
+ export type DateRangePickerProps = BaseDatePickerProps & Omit<DayPickerRangeProps, "mode"> & {
17
18
  defaultRange?: DateRange;
18
19
  getRangeValue?: (range: DateRange | undefined) => {
19
20
  from: string | undefined;
@@ -21,7 +22,7 @@ export type DateRangePickerProps = BaseDatePickerProps & Omit<DayPickerRangeProp
21
22
  };
22
23
  getRangeLabel?: (range: DateRange | undefined) => string | JSX.Element | undefined;
23
24
  };
24
- export type MultipleDatesPickerProps = BaseDatePickerProps & Omit<DayPickerMultipleProps, "mode" | "selected" | "onSelect"> & {
25
+ export type MultipleDatesPickerProps = BaseDatePickerProps & Omit<DayPickerMultipleProps, "mode"> & {
25
26
  defaultDates?: Date[];
26
27
  getDatesValue?: (dates: Date[] | undefined) => string[] | undefined;
27
28
  getDatesLabel?: (dates: Date[] | undefined) => string | JSX.Element | undefined;
@@ -1,3 +1,4 @@
1
1
  export type Theme = "dark" | "light";
2
+ export declare const THEME_COOKIE_NAME = "data-theme";
2
3
  export declare const getTheme: () => Theme | null;
3
4
  export declare const saveTheme: (theme: Theme) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/common",
3
3
  "private": false,
4
- "version": "0.0.31",
4
+ "version": "0.0.33",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -95,6 +95,7 @@
95
95
  "sonner": "^1.4.41",
96
96
  "tailwind-merge": "^2.2.1",
97
97
  "tailwindcss-animate": "^1.0.7",
98
+ "universal-cookie": "^7.1.4",
98
99
  "vaul": "^0.9.0"
99
100
  },
100
101
  "devDependencies": {
@@ -142,5 +143,5 @@
142
143
  "react-dom": "^18.2.0",
143
144
  "typescript": "^5.2.2"
144
145
  },
145
- "gitHead": "06b3dabcfcd2694bf8d0701a392f6b7f01101e7a"
146
+ "gitHead": "169aeecca51d4544bfed02de64e0d9806dd83c6c"
146
147
  }
@@ -21,6 +21,7 @@ export const DatePicker = ({
21
21
  children,
22
22
  getDateValue = (date) => date?.toUTCString(),
23
23
  getDateLabel = (date) => (date ? format(date, "PPP") : undefined),
24
+ triggerClassName,
24
25
  ...props
25
26
  }: DatePickerProps) => {
26
27
  const [date, setDate] = useState<Date | undefined>(defaultDate);
@@ -49,7 +50,11 @@ export const DatePicker = ({
49
50
  outline={outline}
50
51
  variant={variant}
51
52
  disabled={disabled}
52
- className={cn("justify-start", !date && "font-normal")}
53
+ className={cn(
54
+ "justify-start",
55
+ !date && "font-normal",
56
+ triggerClassName
57
+ )}
53
58
  value={dateValue}
54
59
  >
55
60
  {dateLabel ?? <span>{label ?? "Pick a date"}</span>}
@@ -33,6 +33,7 @@ export const DateRangePicker = ({
33
33
  format(range.from, "LLL dd, y")
34
34
  )
35
35
  ) : undefined,
36
+ triggerClassName,
36
37
  ...props
37
38
  }: DateRangePickerProps) => {
38
39
  const [range, setRange] = useState<DateRange | undefined>(defaultRange);
@@ -68,9 +69,13 @@ export const DateRangePicker = ({
68
69
  outline={outline}
69
70
  variant={variant}
70
71
  disabled={disabled}
71
- className={cn("justify-start flex-nowrap", !range && "font-normal")}
72
+ className={cn(
73
+ "justify-start flex-nowrap",
74
+ !range && "font-normal",
75
+ triggerClassName
76
+ )}
72
77
  >
73
- <span className="text-left line-clamp-1">
78
+ <span className="text-left text-ellipsis overflow-hidden text-nowrap">
74
79
  {rangeLabel ?? label ?? "Pick a range"}
75
80
  </span>
76
81
  <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
@@ -59,7 +59,7 @@ export const MultipleDatesPicker = ({
59
59
  !dates?.length && "font-normal"
60
60
  )}
61
61
  >
62
- <span className="text-left line-clamp-1">
62
+ <span className="text-left text-ellipsis overflow-hidden text-nowrap">
63
63
  {rangeLabel ?? label ?? "Pick one or more dates"}
64
64
  </span>
65
65
  <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
@@ -11,10 +11,11 @@ type BaseDatePickerProps = Pick<
11
11
  "variant" | "outline" | "wide" | "size" | "name" | "disabled"
12
12
  > & {
13
13
  label?: string;
14
+ triggerClassName?: string;
14
15
  };
15
16
 
16
17
  export type DatePickerProps = BaseDatePickerProps &
17
- Omit<DayPickerSingleProps, "mode" | "selected" | "onSelect"> & {
18
+ Omit<DayPickerSingleProps, "mode"> & {
18
19
  children?: ({
19
20
  date,
20
21
  setDate,
@@ -28,7 +29,7 @@ export type DatePickerProps = BaseDatePickerProps &
28
29
  };
29
30
 
30
31
  export type DateRangePickerProps = BaseDatePickerProps &
31
- Omit<DayPickerRangeProps, "mode" | "selected" | "onSelect"> & {
32
+ Omit<DayPickerRangeProps, "mode"> & {
32
33
  defaultRange?: DateRange;
33
34
  getRangeValue?: (range: DateRange | undefined) => {
34
35
  from: string | undefined;
@@ -40,7 +41,7 @@ export type DateRangePickerProps = BaseDatePickerProps &
40
41
  };
41
42
 
42
43
  export type MultipleDatesPickerProps = BaseDatePickerProps &
43
- Omit<DayPickerMultipleProps, "mode" | "selected" | "onSelect"> & {
44
+ Omit<DayPickerMultipleProps, "mode"> & {
44
45
  defaultDates?: Date[];
45
46
  getDatesValue?: (dates: Date[] | undefined) => string[] | undefined;
46
47
  getDatesLabel?: (
@@ -1,17 +1,19 @@
1
+ import Cookies from "universal-cookie";
2
+
1
3
  export type Theme = "dark" | "light";
2
4
 
5
+ export const THEME_COOKIE_NAME = "data-theme";
6
+
3
7
  export const getTheme = () => {
4
8
  if (typeof window === "undefined") return null;
5
9
 
6
- let t = window.localStorage.getItem("__theme") as Theme;
7
- if (!t)
8
- t = window.matchMedia("(prefers-color-scheme: dark)")?.matches
9
- ? "dark"
10
- : "light";
11
- return t;
10
+ const cookies = new Cookies();
11
+ const theme = cookies.get(THEME_COOKIE_NAME) as Theme;
12
+ return theme;
12
13
  };
13
14
 
14
15
  export const saveTheme = (theme: Theme) => {
15
- document.body.setAttribute("data-theme", theme);
16
- window.localStorage.setItem("__theme", theme);
16
+ const cookies = new Cookies();
17
+ cookies.set(THEME_COOKIE_NAME, theme, { secure: true });
18
+ document.body.setAttribute(THEME_COOKIE_NAME, theme);
17
19
  };