@g9tm/lynxcontrols-calendar 0.0.0-stage → 2.1.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.
@@ -0,0 +1,80 @@
1
+ import "./calendar.css";
2
+ import { g9IdProps } from "@g9tm/lynxcontrols/base";
3
+ import { G9HScroll } from "@g9tm/lynxcontrols/layout";
4
+ import { useG9Culture } from "@g9tm/lynxcontrols/provider";
5
+ import { G9Chip } from "@g9tm/lynxcontrols/toggle";
6
+ import { formatNumber, getMonthNames } from "@g9tm/lynxcontrols-foundation";
7
+ const PERSIAN = [
8
+ 31,
9
+ 31,
10
+ 31,
11
+ 31,
12
+ 31,
13
+ 31,
14
+ 30,
15
+ 30,
16
+ 30,
17
+ 30,
18
+ 30,
19
+ 30
20
+ ];
21
+ const GREGORIAN = [
22
+ 31,
23
+ 29,
24
+ 31,
25
+ 30,
26
+ 31,
27
+ 30,
28
+ 31,
29
+ 31,
30
+ 30,
31
+ 31,
32
+ 30,
33
+ 31
34
+ ];
35
+ function monthDayLength(calendar, month) {
36
+ var _;
37
+ return null != (_ = ('persian' === calendar ? PERSIAN : GREGORIAN)[month - 1]) ? _ : 0;
38
+ }
39
+ function G9MonthDayPicker(props) {
40
+ const culture = useG9Culture();
41
+ const calendar = 'persian' === culture.calendar ? 'persian' : 'gregorian';
42
+ const months = getMonthNames(calendar, culture);
43
+ const value = props.value;
44
+ const days = value ? monthDayLength(calendar, value.month) : 0;
45
+ const num = (n)=>formatNumber(n, {
46
+ numberingSystem: culture.numberingSystem,
47
+ useGrouping: false
48
+ });
49
+ const id = (suffix)=>props.id ? `${props.id}.${suffix}` : void 0;
50
+ return <view className="g9-month-day" {...g9IdProps(props.id)}>
51
+ <G9HScroll height={40}>
52
+ {months.map((name, i)=>{
53
+ const month = i + 1;
54
+ const on = (null == value ? void 0 : value.month) === month;
55
+ return <G9Chip key={month} {...id(`Month${month}`) ? {
56
+ id: id(`Month${month}`)
57
+ } : {}} className="g9-month-day__chip" text={name} size="sm" selected={on} onPress={()=>{
58
+ var _ref;
59
+ return props.onChange(on ? null : {
60
+ month,
61
+ day: Math.min(null != (_ref = null == value ? void 0 : value.day) ? _ref : 1, monthDayLength(calendar, month))
62
+ });
63
+ }}/>;
64
+ })}
65
+ </G9HScroll>
66
+ {value ? <view className="g9-month-day__days">
67
+ <G9HScroll height={40}>
68
+ {Array.from({
69
+ length: days
70
+ }, (_, i)=>i + 1).map((day)=><G9Chip key={day} {...id(`Day${day}`) ? {
71
+ id: id(`Day${day}`)
72
+ } : {}} className="g9-month-day__chip" text={num(day)} size="sm" appearance={value.day === day ? 'solid' : 'soft'} selected={value.day === day} onPress={()=>props.onChange({
73
+ month: value.month,
74
+ day
75
+ })}/>)}
76
+ </G9HScroll>
77
+ </view> : null}
78
+ </view>;
79
+ }
80
+ export { G9MonthDayPicker, monthDayLength };
@@ -0,0 +1,24 @@
1
+ import { type G9PickerFieldProps } from '@g9tm/lynxcontrols/pickers';
2
+ import { type ReactNode } from '@lynx-js/react';
3
+ /**
4
+ * `+03:30` / `−05:00` for an offset in minutes, in Latin digits like the zone id beside it (the minus is U+2212, read
5
+ * as a sign in RTL text).
6
+ */
7
+ export declare function zoneOffsetLabel(minutes: number): string;
8
+ /** `Asia/Tehran (UTC+03:30)`: the zone id readable (underscores as spaces) with its offset. */
9
+ export declare function zoneLabel(zone: string, offsetMinutes: number | null): string;
10
+ /** Props of {@link G9ZonePicker}. */
11
+ export interface G9ZonePickerProps extends G9PickerFieldProps {
12
+ /** The zone id; `''` = the device's zone (when `deviceText` is given). */
13
+ readonly value: string;
14
+ readonly onChange: (zone: string) => void;
15
+ /** Every zone offered (the app's list, e.g. `Intl.supportedValuesOf('timeZone')` where it exists). */
16
+ readonly zones: readonly string[];
17
+ /** The zone's offset now, in minutes (shown next to its name); without it only names show. */
18
+ readonly offsetOf?: (zone: string) => number;
19
+ /** The first row, «Use the device's zone (Asia/Tehran)», with the value `''`. */
20
+ readonly deviceText?: string;
21
+ }
22
+ /** A searchable time-zone picker: the rows are windowed, so ~420 zones open as fast as ten. */
23
+ export declare function G9ZonePicker(props: G9ZonePickerProps): ReactNode;
24
+ //# sourceMappingURL=zone-picker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zone-picker.d.ts","sourceRoot":"","sources":["../src/zone-picker.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAY,KAAK,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,gBAAgB,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKvD;AAED,+FAA+F;AAC/F,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAG5E;AAID,qCAAqC;AACrC,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,sGAAsG;IACtG,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,8FAA8F;IAC9F,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7C,iFAAiF;IACjF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,+FAA+F;AAC/F,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAmBhE"}
@@ -0,0 +1,34 @@
1
+ import { G9Picker } from "@g9tm/lynxcontrols/pickers";
2
+ import { useMemo } from "@lynx-js/react";
3
+ function zoneOffsetLabel(minutes) {
4
+ const sign = minutes < 0 ? '−' : '+';
5
+ const abs = Math.abs(Math.round(minutes));
6
+ const two = (n)=>String(n).padStart(2, '0');
7
+ return `${sign}${two(Math.floor(abs / 60))}:${two(abs % 60)}`;
8
+ }
9
+ function zoneLabel(zone, offsetMinutes) {
10
+ const name = zone.replace(/_/g, ' ');
11
+ return null === offsetMinutes ? name : `${name} (UTC${zoneOffsetLabel(offsetMinutes)})`;
12
+ }
13
+ const DEVICE = '@device';
14
+ function G9ZonePicker(props) {
15
+ const { value, onChange, zones, offsetOf, deviceText, ...field } = props;
16
+ const items = useMemo(()=>[
17
+ ...deviceText ? [
18
+ {
19
+ key: DEVICE,
20
+ text: deviceText
21
+ }
22
+ ] : [],
23
+ ...zones.map((zone)=>({
24
+ key: zone,
25
+ text: zoneLabel(zone, offsetOf ? offsetOf(zone) : null)
26
+ }))
27
+ ], [
28
+ zones,
29
+ offsetOf,
30
+ deviceText
31
+ ]);
32
+ return <G9Picker {...field} items={items} value={'' === value && deviceText ? DEVICE : value} searchable onValueChange={(key)=>onChange(key === DEVICE || null === key ? '' : key)}/>;
33
+ }
34
+ export { G9ZonePicker, zoneLabel, zoneOffsetLabel };
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@g9tm/lynxcontrols-calendar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.1.0",
4
+ "description": "Calendar controls for G9LynxControls on the culture calendar (Persian or Gregorian): month grids, recurrence, overlap layout, G9MiniMonth, G9MonthView, G9TimeGrid, G9AgendaView, G9DateInput and G9RepeatPicker.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": [
8
+ "**/*.css"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "source": "./src/index.ts",
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.jsx"
15
+ },
16
+ "./model": {
17
+ "source": "./src/model.ts",
18
+ "types": "./dist/model.d.ts",
19
+ "default": "./dist/model.jsx"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "scripts": {
27
+ "build": "rslib build"
28
+ },
29
+ "dependencies": {
30
+ "@g9tm/lynxcontrols-foundation": "2.1.0"
31
+ },
32
+ "peerDependencies": {
33
+ "@g9tm/lynxcontrols": "2.1.0",
34
+ "@lynx-js/react": ">=0.129.3 <0.130.0"
35
+ }
36
+ }