@7shifts/sous-chef 4.5.1 → 4.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.
@@ -1,6 +1,7 @@
1
1
  import React, { MutableRefObject } from 'react';
2
2
  import { BlockedDays, WeekStart } from '../../utils/date';
3
3
  import { CalendarMode, CalendarPlacement } from './types';
4
+ import { HighlightGroup } from '../../utils/highlight';
4
5
  type Props = {
5
6
  mode?: CalendarMode;
6
7
  /** Note that if the calendar is not able to fit in the selected position,
@@ -15,6 +16,9 @@ type Props = {
15
16
  * [doc](https://react-day-picker-v7.netlify.app/api/DayPicker#disabledDays) to see what
16
17
  * values you can use. */
17
18
  disabledDays?: BlockedDays;
19
+ /** Highlight one or more groups of dates, each with its own shape, colour
20
+ * theme, and legend label, e.g. pay days or holidays. */
21
+ highlightedDays?: HighlightGroup[] | HighlightGroup;
18
22
  anchorRef: MutableRefObject<HTMLElement | null>;
19
23
  testId?: string;
20
24
  onMonthChange?: (month: Date) => void;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { HighlightModifier } from '../../../utils/highlight';
3
+ type Props = {
4
+ highlights: HighlightModifier[];
5
+ };
6
+ /** Legend rendered beneath a calendar, one row item per highlight group. */
7
+ declare const CalendarHighlights: ({ highlights }: Props) => React.JSX.Element | null;
8
+ export default CalendarHighlights;
@@ -0,0 +1 @@
1
+ export { default } from './CalendarHighlights';
@@ -1,7 +1,23 @@
1
1
  import { CalendarPlacement } from './types';
2
+ import { Matcher } from 'react-day-picker';
3
+ import { HighlightGroup, HighlightModifier } from '../../utils/highlight';
2
4
  type Position = {
3
5
  left: number;
4
6
  top: number;
5
7
  };
6
8
  export declare const calculateCalendarPosition: (placement: CalendarPlacement, anchorPosition: DOMRect, calendarDimensions?: DOMRect) => Position;
9
+ type HighlightDayPickerProps = {
10
+ /** Pass straight to DayPicker's `modifiers`. */
11
+ modifiers?: Record<string, Matcher>;
12
+ /** Pass straight to DayPicker's `modifiersClassNames`. */
13
+ modifiersClassNames?: Record<string, string>;
14
+ /** Resolved groups for rendering the legend. */
15
+ items: HighlightModifier[];
16
+ };
17
+ /**
18
+ * Builds the DayPicker `modifiers`/`modifiersClassNames` for the given
19
+ * highlight groups, plus the resolved items for the legend. Shared by every
20
+ * calendar component so highlights look and behave identically.
21
+ */
22
+ export declare const buildHighlightDayPickerProps: (highlightedDays?: HighlightGroup[] | HighlightGroup) => HighlightDayPickerProps;
7
23
  export {};
@@ -0,0 +1,25 @@
1
+ /** Day of the week, Sunday = 0 through Saturday = 6 (matches Date.getDay). */
2
+ export type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6;
3
+ type DateMatcher = (date: Date) => boolean;
4
+ /**
5
+ * Matches the nth occurrence of a weekday within its month.
6
+ *
7
+ * @example nthWeekdayOfMonth(1, 1) // first Monday of every month
8
+ * @example nthWeekdayOfMonth(5, 'last') // last Friday of every month
9
+ */
10
+ export declare const nthWeekdayOfMonth: (weekday: Weekday, nth: number | 'last') => DateMatcher;
11
+ /**
12
+ * Matches a weekday on a repeating week interval, aligned to `from`.
13
+ *
14
+ * @example everyOtherWeekday(5, { from: firstPayDay }) // every other Friday
15
+ * @example everyOtherWeekday(1, { interval: 3 }) // every third Monday
16
+ */
17
+ export declare const everyOtherWeekday: (weekday: Weekday, options?: {
18
+ from?: Date;
19
+ interval?: number;
20
+ }) => DateMatcher;
21
+ /** Matches the first day of every month. */
22
+ export declare const firstOfMonth: () => DateMatcher;
23
+ /** Matches the last day of every month. */
24
+ export declare const lastOfMonth: () => DateMatcher;
25
+ export {};
@@ -0,0 +1,47 @@
1
+ import { Matcher } from 'react-day-picker';
2
+ export declare const HIGHLIGHT_SHAPE: {
3
+ readonly CIRCLE: "circle";
4
+ readonly CIRCLE_DASHED: "circle-dashed";
5
+ readonly SQUARE: "square";
6
+ readonly SQUARE_DASHED: "square-dashed";
7
+ readonly OCTAGON: "octagon";
8
+ readonly STAR: "star";
9
+ };
10
+ export type HighlightShape = (typeof HIGHLIGHT_SHAPE)[keyof typeof HIGHLIGHT_SHAPE];
11
+ /** Semantic colour themes for highlight indicators. Mirrors the design
12
+ * system feedback colours so highlights stay on-brand in light and dark. */
13
+ export type HighlightTheme = 'success' | 'danger' | 'warning' | 'info' | 'upsell' | 'neutral';
14
+ export type HighlightGroup = {
15
+ /** Dates to highlight. Accepts any react-day-picker Matcher: a fixed
16
+ * Date, an array of dates, a { from, to } range, { dayOfWeek }, or a
17
+ * (date: Date) => boolean function for custom patterns. Reach for the
18
+ * pattern helpers (nthWeekdayOfMonth, everyOtherWeekday, firstOfMonth,
19
+ * lastOfMonth) for common recurring patterns. */
20
+ dates: Matcher | Matcher[];
21
+ /** Label shown in the legend beneath the calendar, e.g. "Pay Days". */
22
+ label: string;
23
+ /** Semantic colour theme for the indicator. Defaults to 'success'. */
24
+ theme?: HighlightTheme;
25
+ /** Indicator shape. Colour and shape are independent so they can be
26
+ * combined freely — this also aids accessibility by not relying on
27
+ * colour alone to differentiate groups. Defaults to 'circle'. */
28
+ shape?: HighlightShape;
29
+ };
30
+ export declare const DEFAULT_HIGHLIGHT_THEME: HighlightTheme;
31
+ export declare const DEFAULT_HIGHLIGHT_SHAPE: HighlightShape;
32
+ export type HighlightModifier = {
33
+ /** Unique react-day-picker modifier key for this group. */
34
+ key: string;
35
+ /** Matcher that resolves true only for days owned by this group. */
36
+ matcher: (date: Date) => boolean;
37
+ shape: HighlightShape;
38
+ theme: HighlightTheme;
39
+ label: string;
40
+ };
41
+ /**
42
+ * Turns the public `highlightedDays` array into per-group react-day-picker
43
+ * modifiers. When a day matches more than one group, the earliest group in
44
+ * the array wins its indicator (later groups' matchers exclude days already
45
+ * owned by an earlier group), so each day renders a single shape.
46
+ */
47
+ export declare const getHighlightModifiers: (groups: HighlightGroup[]) => HighlightModifier[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@7shifts/sous-chef",
3
- "version": "4.5.1",
3
+ "version": "4.6.0",
4
4
  "description": "7shifts component library",
5
5
  "author": "7shifts",
6
6
  "license": "MIT",