diff --git a/lib/.npmignore b/lib/.npmignore new file mode 100644 index 0000000..73ef37d --- /dev/null +++ b/lib/.npmignore @@ -0,0 +1,4 @@ +*.fixture.js +*.mock.js +*.spec.js +*.test.jsx diff --git a/lib/composeData.d.ts b/lib/composeData.d.ts new file mode 100644 index 0000000..254d4bb --- /dev/null +++ b/lib/composeData.d.ts @@ -0,0 +1,13 @@ +export default function composeData(values: ComposedData, element: HTMLButtonElement | HTMLFieldSetElement | HTMLInputElement | HTMLObjectElement | HTMLOutputElement | HTMLSelectElement | HTMLTextAreaElement, i: Int, collection: HTMLFormControlsCollection): ComposedData; +export namespace FIELD_TAGS { + let FIELDSET: "fieldset"; + let INPUT: "input"; + let SELECT: "select"; + let TEXTAREA: "textarea"; +} +export type Int = number; +export type ComposedData = { + [k: string]: string | number | boolean | (string | number)[] | FileList | ComposedData | null | undefined; +}; +export type FieldTag = (typeof FIELD_TAGS)[keyof typeof FIELD_TAGS]; +//# sourceMappingURL=composeData.d.ts.map \ No newline at end of file diff --git a/lib/composeData.d.ts.map b/lib/composeData.d.ts.map new file mode 100644 index 0000000..86759fa --- /dev/null +++ b/lib/composeData.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"composeData.d.ts","sourceRoot":"","sources":["composeData.js"],"names":[],"mappings":"AAkCA,4CARW,YAAY,WAEZ,iBAAiB,GAAC,mBAAmB,GAAC,gBAAgB,GAAC,iBAAiB,GAAC,iBAAiB,GAAC,iBAAiB,GAAC,mBAAmB,KAEhI,GAAG,cACH,0BAA0B,GACxB,YAAY,CAoFxB;;;;;;;kBAlGY,MAAM;;;;uBAbN,CAAA,iBAAiB,EAAC,MAAM,iBAAiB,CAAC"} \ No newline at end of file diff --git a/lib/composeData.js b/lib/composeData.js index e1fc1c5..09ec34c 100644 --- a/lib/composeData.js +++ b/lib/composeData.js @@ -2,20 +2,21 @@ import _isArray from 'lodash-es/isArray.js'; import _reduce from 'lodash-es/reduce.js'; -export const FIELD_TAGS = { +/** + * @typedef {typeof FIELD_TAGS[keyof typeof FIELD_TAGS]} FieldTag + */ +export const FIELD_TAGS = /** @type {const} */ ({ FIELDSET: 'fieldset', INPUT: 'input', SELECT: 'select', TEXTAREA: 'textarea', -}; +}); const listNameRgx = /\[\d*\]$/; const isListName = (name) => listNameRgx.test(name); /** - * @typedef {number} Integer - */ -/** + * @typedef {number} Int * @typedef {{ [k: string]: Array | boolean | FileList | number | string | null | * undefined | ComposedData }} ComposedData An object with values cast to the type declared by the * field from which the value was derived. Checkboxses and Radios have boolean values. @@ -27,7 +28,7 @@ const isListName = (name) => listNameRgx.test(name); * contains `__exclude: true`, then fields that are read-only will be excluded from the output. * @param {HTMLButtonElement|HTMLFieldSetElement|HTMLInputElement|HTMLObjectElement|HTMLOutputElement|HTMLSelectElement|HTMLTextAreaElement} * element The element currently being processed. - * @param {Integer} i The index of the field in the master list of fields. + * @param {Int} i The index of the field in the master list of fields. * @param {HTMLFormControlsCollection} collection The parent `
` element. * @returns {ComposedData} */ diff --git a/lib/deepDiff.d.ts b/lib/deepDiff.d.ts new file mode 100644 index 0000000..bcd619e --- /dev/null +++ b/lib/deepDiff.d.ts @@ -0,0 +1,2 @@ +export default function deepDiff(oldVals: any, newVals: any, delta?: Record): import('./composeData.js').ComposedData; +//# sourceMappingURL=deepDiff.d.ts.map \ No newline at end of file diff --git a/lib/deepDiff.d.ts.map b/lib/deepDiff.d.ts.map new file mode 100644 index 0000000..b4422f1 --- /dev/null +++ b/lib/deepDiff.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"deepDiff.d.ts","sourceRoot":"","sources":["deepDiff.js"],"names":[],"mappings":"AAcA,qEAJW,OAAO,MAAM,EAAE,KAAK,CAAC,GACnB,OAAO,kBAAkB,EAAE,YAAY,CAwDnD"} \ No newline at end of file diff --git a/lib/deepDiff.js b/lib/deepDiff.js index 6eddeaa..2472694 100755 --- a/lib/deepDiff.js +++ b/lib/deepDiff.js @@ -8,7 +8,7 @@ import _isObject from 'lodash-es/isObject.js'; * * @param {*} oldVals * @param {*} newVals - * @param {object} delta + * @param {Record} delta * @returns {import('./composeData.js').ComposedData} The delta—the difference between old and new. When an old field is absent * in new, the old field is set to `null`. */ diff --git a/lib/react/Button/Button.d.ts b/lib/react/Button/Button.d.ts new file mode 100644 index 0000000..958fdf0 --- /dev/null +++ b/lib/react/Button/Button.d.ts @@ -0,0 +1,37 @@ +declare function Button({ appearance, children: label, className, fluid, icon: Icon, type, variant, ...others }: ButtonProps & import("react").BaseHTMLAttributes): JSX.Element; +declare namespace Button { + let displayName: "Form5Button"; + namespace APPEARANCES { + let AFFIRMING: "affirming"; + let BASIC: "basic"; + let DANGER: "danger"; + let PRIMARY: "primary"; + let WARNING: "warning"; + } + namespace TYPES { + let BUTTON: "button"; + let RESET: "reset"; + let SUBMIT: "submit"; + } + namespace VARIANTS { + let CTA: "cta"; + let GLYPH: "glyph"; + } + function Group({ className, ...props }: import("../Group/Group.jsx").GroupProps & import("react").HTMLAttributes): JSX.Element; +} +export default Button; +export { styles as buttonClasses }; +export type React = typeof import("react"); +export type ButtonProps = { + appearance?: Appearance | undefined; + disabled?: boolean | undefined; + children?: React.ReactNode; + fluid?: boolean | undefined; + icon?: React.ReactNode; + type?: "button" | "reset" | "submit" | undefined; + variant?: Variant | undefined; +}; +export type Appearance = (typeof Button.APPEARANCES)[keyof typeof Button.APPEARANCES]; +export type Type = (typeof Button.TYPES)[keyof typeof Button.TYPES]; +export type Variant = (typeof Button.VARIANTS)[keyof typeof Button.VARIANTS]; +//# sourceMappingURL=Button.d.ts.map \ No newline at end of file diff --git a/lib/react/Button/Button.d.ts.map b/lib/react/Button/Button.d.ts.map new file mode 100644 index 0000000..328c907 --- /dev/null +++ b/lib/react/Button/Button.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["Button.jsx"],"names":[],"mappings":"AA2BA,iHAFW,WAAW,0CAA2B,eA8BhD;;;;;;;;;;;;;;;;;;;IAiCD,4IAEC;;;;;;;;eAzEa,MAAM,SAAS;;WAEf,MAAM,SAAS;;;;yBAyChB,CAAA,OAAO,OAAO,WAAW,EAAC,MAAM,OAAO,OAAO,WAAW,CAAC;mBAU1D,CAAA,OAAO,OAAO,KAAK,EAAC,MAAM,OAAO,OAAO,KAAK,CAAC;sBAQ9C,CAAA,OAAO,OAAO,QAAQ,EAAC,MAAM,OAAO,OAAO,QAAQ,CAAC"} \ No newline at end of file diff --git a/lib/react/Button/Button.jsx b/lib/react/Button/Button.jsx index 1dd8625..801d5cd 100644 --- a/lib/react/Button/Button.jsx +++ b/lib/react/Button/Button.jsx @@ -1,5 +1,4 @@ import { clsx } from 'clsx'; -import PropTypes from 'prop-types'; import Group from '../Group/Group.jsx'; @@ -9,25 +8,34 @@ import styles from './Button.module.css'; export { styles as buttonClasses }; /** - * - * @param {object} props - * @param {APPEARANCE} [props.appearance=Button.APPEARANCES.PRIMARY] - * @param {ReactNode} props.children - * @param {string} props.className - * @param {boolean} [props.fluid=false] - * @param {ReactNode} props.icon - * @param {HTMLButtonElement['type']} [props.type=Button.TYPES.BUTTON] - * @param {VARIANT} [props.variant=Button.VARIANTS.CTA] - * @param {import('react').HTMLProps} props.others - * @returns {HTMLButtonElement} + * @typedef {import('react')} React + */ + +/** + * @typedef {object} ButtonProps + * @property {Appearance} [ButtonProps.appearance=Button.APPEARANCES.PRIMARY] + * @property {boolean} [ButtonProps.disabled] + * @property {React.ReactNode} [ButtonProps.children] + * @property {boolean} [ButtonProps.fluid=false] + * @property {React.ReactNode} [ButtonProps.icon] + * @property {HTMLButtonElement['type']} [ButtonProps.type=Button.TYPES.BUTTON] + * @property {Variant} [ButtonProps.variant=Button.VARIANTS.CTA] + */ + +/** + * @param {ButtonProps & React.BaseHTMLAttributes} props */ export default function Button({ + appearance = Button.APPEARANCES.PRIMARY, children: label, className, fluid, icon: Icon, + type = Button.TYPES.BUTTON, + variant = Button.VARIANTS.CTA, ...others }) { + Object.assign(others, { appearance, type, variant }); return (