uikit-react-public 0.11.16 → 0.11.20

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.
Files changed (52) hide show
  1. package/dist/components/Datepicker/Datepicker.d.ts +5 -1
  2. package/dist/components/Datepicker/Datepicker.stories.d.ts +8 -1
  3. package/dist/components/Datepicker/Datepicker.types.d.ts +7 -0
  4. package/dist/components/Datepicker/index.d.ts +1 -0
  5. package/dist/components/Datepicker/subcomponents/AcademicWeek.d.ts +5 -0
  6. package/dist/components/Datepicker/subcomponents/AcademicWeeks.d.ts +7 -0
  7. package/dist/components/Datepicker/subcomponents/CalendarGrid/CalendarGrid.d.ts +3 -1
  8. package/dist/components/Datepicker/subcomponents/CalendarMenu/CalendarMenu.d.ts +5 -1
  9. package/dist/components/Datepicker/subcomponents/Day/Day.d.ts +4 -2
  10. package/dist/components/Datepicker/subcomponents/Day/Day.stories.d.ts +9 -1
  11. package/dist/components/Datepicker/subcomponents/EventDot.d.ts +6 -0
  12. package/dist/components/Datepicker/utils/getAcademicWeekNumbers/getAcademicWeekNumbers.d.ts +24 -0
  13. package/dist/components/Datepicker/utils/getAcademicWeekNumbers/getAcademicWeekNumbers.test.d.ts +1 -0
  14. package/dist/components/Datepicker/utils/index.d.ts +1 -0
  15. package/dist/components/Header/Header.d.ts +5 -4
  16. package/dist/components/Header/index.d.ts +1 -1
  17. package/dist/components/Select/Select.stories.d.ts +1 -1
  18. package/dist/components/Select/Select.types.d.ts +10 -50
  19. package/dist/components/Select/index.d.ts +1 -1
  20. package/dist/components/Select/subcomponents/CustomSelect.d.ts +2 -1
  21. package/dist/index.js +1865 -1748
  22. package/lib/components/Datepicker/Datepicker.stories.tsx +133 -0
  23. package/lib/components/Datepicker/Datepicker.tsx +23 -46
  24. package/lib/components/Datepicker/Datepicker.types.ts +9 -0
  25. package/lib/components/Datepicker/__tests__/__snapshots__/Datepicker.test.tsx.snap +487 -378
  26. package/lib/components/Datepicker/index.ts +1 -0
  27. package/lib/components/Datepicker/subcomponents/AcademicWeek.tsx +36 -0
  28. package/lib/components/Datepicker/subcomponents/AcademicWeeks.tsx +44 -0
  29. package/lib/components/Datepicker/subcomponents/CalendarGrid/CalendarGrid.tsx +9 -14
  30. package/lib/components/Datepicker/subcomponents/CalendarMenu/CalendarMenu.tsx +32 -6
  31. package/lib/components/Datepicker/subcomponents/Day/Day.stories.tsx +23 -0
  32. package/lib/components/Datepicker/subcomponents/Day/Day.tsx +31 -7
  33. package/lib/components/Datepicker/subcomponents/EventDot.tsx +40 -0
  34. package/lib/components/Datepicker/utils/getAcademicWeekNumbers/getAcademicWeekNumbers.test.ts +104 -0
  35. package/lib/components/Datepicker/utils/getAcademicWeekNumbers/getAcademicWeekNumbers.ts +85 -0
  36. package/lib/components/Datepicker/utils/index.ts +1 -0
  37. package/lib/components/Header/Header.tsx +32 -33
  38. package/lib/components/Header/HeaderMenu.tsx +9 -2
  39. package/lib/components/Header/__tests__/__snapshots__/Header.test.tsx.snap +40 -48
  40. package/lib/components/Header/index.ts +5 -1
  41. package/lib/components/Select/Select.stories.tsx +38 -39
  42. package/lib/components/Select/Select.tsx +4 -18
  43. package/lib/components/Select/Select.types.ts +30 -69
  44. package/lib/components/Select/__tests__/Select.test.tsx +6 -6
  45. package/lib/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +1 -1
  46. package/lib/components/Select/index.ts +1 -1
  47. package/lib/components/Select/subcomponents/CustomSelect.tsx +22 -12
  48. package/lib/components/Select/subcomponents/NativeSelect.tsx +7 -3
  49. package/lib/components/Select/subcomponents/Panel.tsx +4 -4
  50. package/lib/components/Select/subcomponents/VisibleField.tsx +1 -1
  51. package/package.json +3 -3
  52. package/LICENSE +0 -9
@@ -1,4 +1,5 @@
1
1
  import { InputHTMLAttributes } from 'react';
2
+ import { CalendarEvent, AcademicWeek } from './Datepicker.types';
2
3
  export declare const NAME = "ucl-datepicker";
3
4
  export interface DatepickerProps extends InputHTMLAttributes<HTMLInputElement> {
4
5
  date: Date | null | undefined;
@@ -6,7 +7,10 @@ export interface DatepickerProps extends InputHTMLAttributes<HTMLInputElement> {
6
7
  maxDate?: Date | null | undefined;
7
8
  onDateChange: (date: Date | null | undefined) => void;
8
9
  native?: boolean;
10
+ events?: CalendarEvent[];
11
+ showAcademicWeeks?: boolean;
12
+ academicWeeks?: AcademicWeek[];
9
13
  testId?: string;
10
14
  }
11
- declare const _default: import('react').MemoExoticComponent<({ date, minDate, maxDate, onDateChange, native, testId, className, ...props }: DatepickerProps) => import("react/jsx-runtime").JSX.Element>;
15
+ declare const _default: import('react').MemoExoticComponent<({ date, minDate, maxDate, onDateChange, native, events, showAcademicWeeks, academicWeeks, testId, className, ...props }: DatepickerProps) => import("react/jsx-runtime").JSX.Element>;
12
16
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import { StoryObj } from '@storybook/react';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: import('react').MemoExoticComponent<({ date, minDate, maxDate, onDateChange, native, testId, className, ...props }: import('./Datepicker').DatepickerProps) => import("react/jsx-runtime").JSX.Element>;
4
+ component: import('react').MemoExoticComponent<({ date, minDate, maxDate, onDateChange, native, events, showAcademicWeeks, academicWeeks, testId, className, ...props }: import('./Datepicker').DatepickerProps) => import("react/jsx-runtime").JSX.Element>;
5
5
  parameters: {
6
6
  layout: string;
7
7
  };
@@ -26,6 +26,11 @@ declare const meta: {
26
26
  type: "boolean";
27
27
  };
28
28
  };
29
+ showAcademicWeeks: {
30
+ control: {
31
+ type: "boolean";
32
+ };
33
+ };
29
34
  };
30
35
  tags: string[];
31
36
  };
@@ -33,3 +38,5 @@ export default meta;
33
38
  type Story = StoryObj<typeof meta>;
34
39
  export declare const Default: Story;
35
40
  export declare const AsNative: Story;
41
+ export declare const WithEvents: Story;
42
+ export declare const WithAcademicWeeks: Story;
@@ -0,0 +1,7 @@
1
+ export type CalendarEvent = {
2
+ date: string;
3
+ };
4
+ export type AcademicWeek = {
5
+ start: string;
6
+ number: number;
7
+ };
@@ -1,2 +1,3 @@
1
1
  export { default } from './Datepicker';
2
2
  export type { DatepickerProps } from './Datepicker';
3
+ export type { CalendarEvent, AcademicWeek } from './Datepicker.types';
@@ -0,0 +1,5 @@
1
+ interface AcademicWeekProps {
2
+ weekNumber?: number | null;
3
+ }
4
+ declare const AcademicWeek: ({ weekNumber }: AcademicWeekProps) => import("react/jsx-runtime").JSX.Element;
5
+ export default AcademicWeek;
@@ -0,0 +1,7 @@
1
+ import { AcademicWeek as AcademicWeekType } from '../Datepicker.types';
2
+ interface AcademicWeeksProps {
3
+ date: Date;
4
+ academicWeeks: AcademicWeekType[];
5
+ }
6
+ declare const AcademicWeeks: ({ date, academicWeeks }: AcademicWeeksProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default AcademicWeeks;
@@ -1,6 +1,8 @@
1
+ import { CalendarEvent } from '../../Datepicker.types';
1
2
  interface CalendarGridProps {
2
3
  date: Date | null | undefined;
3
4
  onDatePick: (date: Date) => void;
5
+ events: CalendarEvent[];
4
6
  }
5
- declare const CalendarGrid: ({ date, onDatePick, }: CalendarGridProps) => import("react/jsx-runtime").JSX.Element;
7
+ declare const CalendarGrid: ({ date, onDatePick, events }: CalendarGridProps) => import("react/jsx-runtime").JSX.Element;
6
8
  export default CalendarGrid;
@@ -1,8 +1,12 @@
1
+ import { CalendarEvent, AcademicWeek } from '../../Datepicker.types';
1
2
  interface CalendarMenuProps {
2
3
  date: Date | null | undefined;
3
4
  setDate: (date: Date) => void;
4
5
  onDatePick: () => void;
6
+ events: CalendarEvent[];
7
+ showAcademicWeeks?: boolean;
8
+ academicWeeks: AcademicWeek[];
5
9
  testId?: string;
6
10
  }
7
- declare const CalendarMenu: ({ date, setDate, onDatePick, testId, }: CalendarMenuProps) => import("react/jsx-runtime").JSX.Element;
11
+ declare const CalendarMenu: ({ date, setDate, onDatePick, events, showAcademicWeeks, academicWeeks, testId, }: CalendarMenuProps) => import("react/jsx-runtime").JSX.Element;
8
12
  export default CalendarMenu;
@@ -1,10 +1,12 @@
1
+ import { CalendarEvent } from '../../Datepicker.types';
1
2
  export interface DayProps {
2
3
  date: Date | null | undefined;
4
+ onPick?: (date: Date) => void;
3
5
  isSelected?: boolean;
4
6
  isToday?: boolean;
5
7
  isInCurrentMonth?: boolean;
6
8
  isDisabled?: boolean;
7
- onPick?: (date: Date) => void;
9
+ events?: CalendarEvent[];
8
10
  }
9
- declare const Day: ({ date, isSelected, isToday, isInCurrentMonth, isDisabled, onPick, }: DayProps) => import("react/jsx-runtime").JSX.Element;
11
+ declare const Day: ({ date, onPick, isSelected, isToday, isInCurrentMonth, isDisabled, events, }: DayProps) => import("react/jsx-runtime").JSX.Element;
10
12
  export default Day;
@@ -1,7 +1,14 @@
1
1
  import { StoryObj } from '@storybook/react';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: ({ date, isSelected, isToday, isInCurrentMonth, isDisabled, onPick, }: import('./Day').DayProps) => import("react/jsx-runtime").JSX.Element;
4
+ component: ({ date, onPick, isSelected, isToday, isInCurrentMonth, isDisabled, events, }: import('./Day').DayProps) => import("react/jsx-runtime").JSX.Element;
5
+ argTypes: {
6
+ events: {
7
+ table: {
8
+ disable: true;
9
+ };
10
+ };
11
+ };
5
12
  };
6
13
  export default meta;
7
14
  type Story = StoryObj<typeof meta>;
@@ -10,4 +17,5 @@ export declare const Selected: Story;
10
17
  export declare const Today: Story;
11
18
  export declare const Disabled: Story;
12
19
  export declare const NotInCurrentMonth: Story;
20
+ export declare const WithEventDots: Story;
13
21
  export declare const AlertOnPick: Story;
@@ -0,0 +1,6 @@
1
+ type EventDotProps = {
2
+ inverted: boolean;
3
+ inCurrentMonth: boolean;
4
+ };
5
+ declare const EventDot: ({ inverted, inCurrentMonth }: EventDotProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default EventDot;
@@ -0,0 +1,24 @@
1
+ import { AcademicWeek } from '../../Datepicker.types';
2
+ /**
3
+ * Returns the Monday for the week of the given date.
4
+ * For example:
5
+ * - If the input date is a Wednesday, it returns the Monday of that week.
6
+ * - If the input date is already a Monday, it returns that date.
7
+ * @param {Date} d - The input date.
8
+ * @returns {Date} The Monday of the week of the input date.
9
+ */
10
+ export declare const getMonday: (d: Date) => Date;
11
+ /**
12
+ * Calculates the academic week numbers for each week displayed in a calendar month.
13
+ * Used by `<AcademicWeeks />` component in the Datepicker.
14
+ * It determines the Mondays of each week shown in the calendar for the `targetDate`'s month.
15
+ * Then, it maps these Mondays to the corresponding academic week number from the `academicWeeks` array.
16
+ * If an academic week is not found for a given Monday, `undefined` is used, in place in the returned array.
17
+ *
18
+ * @param {AcademicWeek[]} academicWeeks - An array of academic week objects, each with a `start` date and `number`.
19
+ * @param {Date} targetDate - The date used to generate the calendar display.
20
+ * @returns {(number | undefined)[]} An array of academic week numbers or `undefined` for each week in the calendar display.
21
+ * Returns an empty array if `academicWeeks` is empty or `targetDate` is invalid, with console warnings, in the interest of safe usage.
22
+ */
23
+ declare const getAcademicWeekNumbers: (academicWeeks: AcademicWeek[], targetDate: Date) => (number | undefined)[];
24
+ export default getAcademicWeekNumbers;
@@ -1,2 +1,3 @@
1
1
  export { default as getDatesForCalendarGrid } from './getDatesForCalendarGrid/getDatesForCalendarGrid';
2
2
  export { default as parseDate } from './parseDateForDateField/parseDateForDateField';
3
+ export { default as getAcademicWeekNumbers } from './getAcademicWeekNumbers/getAcademicWeekNumbers';
@@ -1,14 +1,15 @@
1
- import { default as React, HTMLAttributes } from 'react';
1
+ import { HTMLAttributes } from 'react';
2
2
  import { default as HeaderMenu } from './HeaderMenu';
3
3
  export declare const NAME = "ucl-uikit-header";
4
- export declare const HEADER_TOP_HEIGHT = 72;
5
- export declare const Z_INDEX = 3;
4
+ export declare const HEADER_DESKTOP_HEIGHT_PX = 72;
5
+ export declare const HEADER_MOBILE_HEIGHT_PX = 48;
6
+ export declare const DEFAULT_Z_INDEX = 3;
6
7
  export interface HeaderProps extends HTMLAttributes<HTMLElement> {
7
8
  title?: string;
8
9
  fixed?: boolean;
9
10
  testId?: string;
10
11
  }
11
- declare const MemoAppHeader: React.MemoExoticComponent<({ title, fixed, testId, className, children, ...props }: HeaderProps) => import("react/jsx-runtime").JSX.Element>;
12
+ declare const MemoAppHeader: import('react').MemoExoticComponent<({ title, fixed, testId, className, children, ...props }: HeaderProps) => import("react/jsx-runtime").JSX.Element>;
12
13
  export interface IHeaderSubComponents {
13
14
  Menu: typeof HeaderMenu;
14
15
  }
@@ -1,3 +1,3 @@
1
1
  export { default } from './Header';
2
- export { HEADER_TOP_HEIGHT } from './Header';
2
+ export { HEADER_DESKTOP_HEIGHT_PX, HEADER_MOBILE_HEIGHT_PX, DEFAULT_Z_INDEX, } from './Header';
3
3
  export type { HeaderProps } from './Header';
@@ -41,7 +41,7 @@ declare const meta: {
41
41
  value: undefined;
42
42
  onChange: () => void;
43
43
  options: {
44
- text: string;
44
+ label: string;
45
45
  value: string;
46
46
  }[];
47
47
  };
@@ -7,7 +7,7 @@ export type OptionData = {
7
7
  /**
8
8
  * Display text shown to the user
9
9
  */
10
- text: string;
10
+ label: string;
11
11
  /**
12
12
  * Data-friendly value that is returned when the option is selected
13
13
  * We assume this will be submitted to a server or used in some other way
@@ -20,12 +20,6 @@ export type OptionData = {
20
20
  */
21
21
  icon?: React.ReactNode;
22
22
  };
23
- /**
24
- * Utility type we expose to developers
25
- * We expect this to be used in typing event handlers
26
- * This only applies to the top-level <Select> component
27
- */
28
- export type SelectEvent = React.ChangeEvent<HTMLSelectElement> | React.MouseEvent | React.KeyboardEvent;
29
23
  /**
30
24
  * Top level props that <Select> accepts when implemented
31
25
  */
@@ -34,20 +28,6 @@ interface BaseSelectProps {
34
28
  * An array of option data, to be rendered either natively or custom
35
29
  */
36
30
  options: OptionData[];
37
- /**
38
- * The currently selected value
39
- * This determines which option is shown when the select is closed
40
- */
41
- value: string | undefined | null;
42
- /**
43
- * Generic onChange that splits into native and custom versions
44
- * The original event is exposed, and the value always returns the value of the selected option
45
- */
46
- onChange: (event: SelectEvent, value: string) => void;
47
- /**
48
- * Prevents use, including focus events
49
- */
50
- disabled?: boolean | undefined;
51
31
  /**
52
32
  * Placeholder text shown when no option is selected
53
33
  * Displayed in visible field of custom implementation
@@ -64,51 +44,31 @@ interface BaseSelectProps {
64
44
  * as `data-testid`
65
45
  */
66
46
  testId?: string;
67
- /**
68
- * Optional className for styling
69
- * This is passed to the root element of the component
70
- * for additional CSS styling via Emotion.
71
- */
72
- className?: string;
73
47
  /**
74
48
  * Native flag determines which implementation to use
75
49
  */
76
50
  native?: boolean;
77
51
  }
78
- export type SelectProps = BaseSelectProps & (({
79
- native: true;
80
- ref?: React.RefObject<HTMLSelectElement | null>;
81
- } & Omit<React.SelectHTMLAttributes<HTMLSelectElement>, keyof BaseSelectProps>) | ({
82
- native?: false;
83
- ref?: React.RefObject<HTMLDivElement | null>;
84
- } & Omit<React.HTMLAttributes<HTMLDivElement>, keyof BaseSelectProps>));
85
52
  /**
86
53
  * Internal props for the custom implementation, with <div> as root element
87
54
  * onChange already exists on <div>. We override it.
88
55
  */
89
- export interface CustomSelectProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
90
- options: OptionData[];
91
- value: string | undefined | null;
92
- onChange: (event: React.MouseEvent | React.KeyboardEvent, value: string) => void;
56
+ export type CustomSelectProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & BaseSelectProps & {
57
+ native?: false;
58
+ value?: string | number;
93
59
  disabled?: boolean;
94
- placeholder?: string;
95
- width?: number;
96
- testId?: string;
97
- className?: string;
60
+ onValueChange?: (value: string, ev: React.UIEvent) => void;
98
61
  ref?: React.RefObject<HTMLDivElement | null>;
99
- }
62
+ };
100
63
  /**
101
64
  * Internal props for native implementation, with <select> as root element
102
65
  * Default props like value and onChange are passed to the <select> element automatically
103
66
  */
104
- export interface NativeSelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
105
- options: OptionData[];
106
- placeholder?: string;
107
- width?: number;
108
- testId?: string;
109
- className?: string;
67
+ export type NativeSelectProps = React.SelectHTMLAttributes<HTMLSelectElement> & BaseSelectProps & {
68
+ native: true;
110
69
  ref?: React.RefObject<HTMLSelectElement | null>;
111
- }
70
+ };
71
+ export type SelectProps = NativeSelectProps | CustomSelectProps;
112
72
  /**
113
73
  * Each option as displayed in the Panel of <CustomSelect>
114
74
  * Roughly equivalent to a custom version of <option>
@@ -1,2 +1,2 @@
1
1
  export { default } from './Select';
2
- export type { SelectProps, OptionData, SelectEvent } from './Select.types';
2
+ export type { SelectProps, OptionData } from './Select.types';
@@ -1,3 +1,4 @@
1
1
  import { CustomSelectProps } from '../Select.types';
2
- declare const CustomSelect: ({ value, options, onChange, disabled, placeholder, width, testId, className, ref, ...props }: CustomSelectProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const DEFAULT_WIDTH_PX = 200;
3
+ declare const CustomSelect: ({ value, options, onValueChange, disabled, placeholder, width, testId, className, ref, ...props }: CustomSelectProps) => import("react/jsx-runtime").JSX.Element;
3
4
  export default CustomSelect;