@campfire-interactive/inputs 0.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.
- package/dist/index.d.ts +39 -0
- package/dist/index.js +57 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
type DatePickerMode = 'date' | 'datetime' | 'time' | 'month' | 'quarter' | 'year';
|
|
4
|
+
interface IDatePicker {
|
|
5
|
+
/** Stored value as a canonical string in the format chosen for `mode`. */
|
|
6
|
+
value?: string | null;
|
|
7
|
+
/** Fires with the canonical string, or null when cleared. */
|
|
8
|
+
onChange: (value: string | null) => void;
|
|
9
|
+
/** Picker behavior. Default: 'date'. */
|
|
10
|
+
mode?: DatePickerMode;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
id?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Inclusive lower bound (any date inside the target unit). */
|
|
16
|
+
minDate?: Date;
|
|
17
|
+
/** Inclusive upper bound. */
|
|
18
|
+
maxDate?: Date;
|
|
19
|
+
/** Show the inline clear ('×') button. Default: true. */
|
|
20
|
+
isClearable?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Override the date-fns format string used to (de)serialize the value.
|
|
23
|
+
* If unset, the per-mode default (see comments on `DatePickerMode`) is used.
|
|
24
|
+
* Locale-aware tokens (e.g., MMM, QQQ) are honored — quote literals with
|
|
25
|
+
* single quotes (e.g., "'Q'Q yyyy") to keep them stable across locales.
|
|
26
|
+
*/
|
|
27
|
+
format?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Alias kept for ergonomic React naming. */
|
|
30
|
+
type DatePickerProps = IDatePicker;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Date / quarter / year / time picker. Wraps `react-datepicker`. The contract
|
|
34
|
+
* is the `DatePickerProps` interface in `./types.ts` — nothing react-datepicker
|
|
35
|
+
* specific leaks to consumers.
|
|
36
|
+
*/
|
|
37
|
+
declare function DatePicker(props: DatePickerProps): react_jsx_runtime.JSX.Element;
|
|
38
|
+
|
|
39
|
+
export { DatePicker, type DatePickerMode, type DatePickerProps, type IDatePicker };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/DatePicker.tsx
|
|
2
|
+
import ReactDatePicker from "react-datepicker";
|
|
3
|
+
import { format as fmt, parse as parseDate, isValid } from "date-fns";
|
|
4
|
+
import "react-datepicker/dist/react-datepicker.css";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var MODE_DEFAULTS = {
|
|
7
|
+
date: { format: "yyyy-MM-dd", placeholder: "YYYY-MM-DD" },
|
|
8
|
+
datetime: { format: "yyyy-MM-dd HH:mm", placeholder: "YYYY-MM-DD HH:mm" },
|
|
9
|
+
time: { format: "HH:mm", placeholder: "HH:mm", flag: "showTimeSelectOnly" },
|
|
10
|
+
month: { format: "yyyy-MM", placeholder: "YYYY-MM", flag: "showMonthYearPicker" },
|
|
11
|
+
// Literal "Q" + numeric quarter (1-4) + 4-digit year. Locale-independent.
|
|
12
|
+
quarter: { format: "'Q'Q yyyy", placeholder: "Q1 2024", flag: "showQuarterYearPicker" },
|
|
13
|
+
year: { format: "yyyy", placeholder: "YYYY", flag: "showYearPicker" }
|
|
14
|
+
};
|
|
15
|
+
var toDate = (value, formatStr) => {
|
|
16
|
+
if (!value) return null;
|
|
17
|
+
const d = parseDate(value, formatStr, /* @__PURE__ */ new Date());
|
|
18
|
+
return isValid(d) ? d : null;
|
|
19
|
+
};
|
|
20
|
+
var toCanonicalString = (date, formatStr) => date && isValid(date) ? fmt(date, formatStr) : null;
|
|
21
|
+
function DatePicker(props) {
|
|
22
|
+
const mode = props.mode ?? "date";
|
|
23
|
+
const defaults = MODE_DEFAULTS[mode];
|
|
24
|
+
const formatStr = props.format ?? defaults.format;
|
|
25
|
+
const placeholder = props.placeholder ?? defaults.placeholder;
|
|
26
|
+
const modeProps = {};
|
|
27
|
+
if (defaults.flag) modeProps[defaults.flag] = true;
|
|
28
|
+
if (mode === "datetime") modeProps.showTimeSelect = true;
|
|
29
|
+
if (mode === "time") {
|
|
30
|
+
modeProps.showTimeSelect = true;
|
|
31
|
+
modeProps.timeIntervals = 15;
|
|
32
|
+
}
|
|
33
|
+
const selected = toDate(props.value ?? null, formatStr);
|
|
34
|
+
const handleChange = (d) => props.onChange(toCanonicalString(d, formatStr));
|
|
35
|
+
const Picker = ReactDatePicker;
|
|
36
|
+
return /* @__PURE__ */ jsx(
|
|
37
|
+
Picker,
|
|
38
|
+
{
|
|
39
|
+
id: props.id,
|
|
40
|
+
selected: selected ?? void 0,
|
|
41
|
+
onChange: handleChange,
|
|
42
|
+
placeholderText: placeholder,
|
|
43
|
+
disabled: props.disabled,
|
|
44
|
+
minDate: props.minDate,
|
|
45
|
+
maxDate: props.maxDate,
|
|
46
|
+
isClearable: props.isClearable ?? true,
|
|
47
|
+
dateFormat: formatStr,
|
|
48
|
+
className: props.className,
|
|
49
|
+
wrapperClassName: "cfi-datepicker-wrapper",
|
|
50
|
+
popperClassName: "cfi-datepicker-popper",
|
|
51
|
+
...modeProps
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
DatePicker
|
|
57
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@campfire-interactive/inputs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared input components for Campfire Suite (date picker, etc.)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup",
|
|
19
|
+
"dev": "tsup --watch"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
23
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"date-fns": "^4.1.0",
|
|
27
|
+
"react-datepicker": "^9.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/react": "^19.0.0",
|
|
31
|
+
"react": "^19.0.0",
|
|
32
|
+
"react-dom": "^19.0.0",
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^5.0.0"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"registry": "https://registry.npmjs.org",
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|