@happeouikit/form-elements 2.3.37 → 2.3.38

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,4 +1,4 @@
1
- import { CSSProperties } from "react";
1
+ import { ChangeEvent, CSSProperties } from "react";
2
2
  interface BaseCheckboxProps {
3
3
  label?: string;
4
4
  subtitle?: string;
@@ -6,7 +6,7 @@ interface BaseCheckboxProps {
6
6
  indeterminate?: boolean;
7
7
  disabled?: boolean;
8
8
  background?: string;
9
- onChange: (newVal: boolean) => void | any;
9
+ onChange?: (event: ChangeEvent<HTMLInputElement>, newVal: boolean) => void | any;
10
10
  checked: boolean;
11
11
  style?: CSSProperties;
12
12
  id?: string;
@@ -29,7 +29,7 @@ export interface CheckboxGroupOption {
29
29
  value: string;
30
30
  background?: string;
31
31
  disabled?: boolean;
32
- onChange?: (newVal: boolean) => void;
32
+ onChange?: (event: ChangeEvent<HTMLInputElement>, newVal: boolean) => void;
33
33
  }
34
34
  export interface CheckboxGroupProps {
35
35
  value?: string[];
@@ -1,7 +1,7 @@
1
1
  import PropTypes from "prop-types";
2
2
  import { RadioButtonProps } from "./RadioButton.types";
3
3
  declare const RadioButton: {
4
- ({ label, subtitle, description, background, id, ...props }: RadioButtonProps): import("react/jsx-runtime").JSX.Element;
4
+ ({ label, subtitle, description, background, id, onChange, ...props }: RadioButtonProps): import("react/jsx-runtime").JSX.Element;
5
5
  propTypes: {
6
6
  label: PropTypes.Requireable<PropTypes.ReactNodeLike>;
7
7
  subtitle: PropTypes.Requireable<PropTypes.ReactNodeLike>;
@@ -5,5 +5,6 @@ export interface RadioButtonProps {
5
5
  description?: React.ReactNode;
6
6
  id?: string;
7
7
  background?: string;
8
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>, newVal: boolean) => void | any;
8
9
  [key: string]: any;
9
10
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export interface BaseSwitchProps {
2
3
  tabIndex?: number;
3
4
  id?: string;
@@ -10,7 +11,7 @@ export interface BaseSwitchProps {
10
11
  "data-tracker"?: string;
11
12
  "data-testid"?: string;
12
13
  required?: boolean;
13
- onChange?: (newValue: boolean) => void | any;
14
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>, newVal: boolean) => void | any;
14
15
  "aria-label"?: string;
15
16
  "aria-expanded"?: boolean;
16
17
  "aria-controls"?: string;
package/dist/index.cjs.js CHANGED
@@ -212,7 +212,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
212
212
  color: ${({hoverColor:e})=>e||N.active};
213
213
  text-decoration: underline;
214
214
  }
215
- `;_a.propTypes={color:P.string,hoverColor:P.string,underline:P.bool,children:P.node};_a.defaultProps={color:N.active,hoverColor:N.active,underline:!1};const Ff=({label:e,subtitle:t,description:r,tabIndex:n,id:a,disabled:i,checked:o,defaultChecked:s,required:u,onChange:l,background:c,"data-tip":d,"data-tip-disable":m,"data-testid":p,...h})=>{const g=f.useRef(null),v=f.useCallback(C=>{if(!i&&(C.preventDefault(),g.current)){const k=!g.current.checked;C.currentTarget.setAttribute("aria-checked",k.toString()),g.current.checked=k,l==null||l(k)}},[l]),b=f.useCallback(C=>{C.key.match(/enter|spacebar|\W{1}/i)&&v(C)},[v]),I=f.useMemo(()=>a||Ot(),[a]);return W.jsxs(Lf,{background:c,children:[W.jsx(Rf,{"aria-hidden":"true",ref:g,type:"checkbox",tabIndex:-1,disabled:i,checked:o,required:u,id:I,"data-testid":p,"aria-describedby":r?`${I}_description`:void 0}),W.jsx(Ln,{type:"button",role:"switch","aria-checked":o||s||!1,onKeyDown:b,onClick:v,disabled:i,background:c,...h}),e&&W.jsxs(Gf,{children:[W.jsxs(Bf,{children:[e&&W.jsx(Vf,{bold:!0,htmlFor:I,"data-tip":d,"data-tip-disable":m,onClick:v,children:e}),t&&W.jsx(Wf,{children:t})]}),r&&W.jsx(Yf,{id:`${I}_description`,children:r})]})]})},Rf=S.input`
215
+ `;_a.propTypes={color:P.string,hoverColor:P.string,underline:P.bool,children:P.node};_a.defaultProps={color:N.active,hoverColor:N.active,underline:!1};const Ff=({label:e,subtitle:t,description:r,tabIndex:n,id:a,disabled:i,checked:o,defaultChecked:s,required:u,onChange:l,background:c,"data-tip":d,"data-tip-disable":m,"data-testid":p,...h})=>{const g=f.useRef(null),v=f.useCallback(C=>{if(!i&&(C.preventDefault(),g.current)){const k=!g.current.checked;C.currentTarget.setAttribute("aria-checked",k.toString()),g.current.checked=k;const y={...C,target:{...g.current,checked:k,id:I}};typeof l=="function"&&l(y,k)}},[l]),b=f.useCallback(C=>{C.key.match(/enter|spacebar|\W{1}/i)&&v(C)},[v]),I=f.useMemo(()=>a||Ot(),[a]);return W.jsxs(Lf,{background:c,children:[W.jsx(Rf,{"aria-hidden":"true",ref:g,type:"checkbox",tabIndex:-1,disabled:i,checked:o,required:u,id:I,"data-testid":p,"aria-describedby":r?`${I}_description`:void 0}),W.jsx(Ln,{type:"button",role:"switch","aria-checked":o||s||!1,onKeyDown:b,onClick:v,disabled:i,background:c,...h}),e&&W.jsxs(Gf,{children:[W.jsxs(Bf,{children:[e&&W.jsx(Vf,{bold:!0,htmlFor:I,"data-tip":d,"data-tip-disable":m,onClick:v,children:e}),t&&W.jsx(Wf,{children:t})]}),r&&W.jsx(Yf,{id:`${I}_description`,children:r})]})]})},Rf=S.input`
216
216
  position: absolute;
217
217
  opacity: 0;
218
218
  height: 0;
@@ -229,6 +229,11 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
229
229
  border: 2px solid ${({background:e})=>e||"var(--color-stroke)"};
230
230
  border-radius: var(--radius-pill);
231
231
 
232
+ :active {
233
+ transform: none;
234
+ box-shadow: none;
235
+ }
236
+
232
237
  :before {
233
238
  position: absolute;
234
239
  content: "";
@@ -305,10 +310,11 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
305
310
 
306
311
  input:disabled + ${Ln} {
307
312
  cursor: not-allowed;
308
- border-color: var(--color-disabled-text-on-light);
313
+ border-color: transparent;
309
314
  background-color: var(--color-disabled-text-on-light);
310
315
  }
311
- `,fs=({label:e,subtitle:t,description:r,indeterminate:n,onChange:a,style:i,disabled:o,checked:s,id:u,background:l,"data-tip":c,"data-tip-disable":d,...m})=>{const p=f.useRef(null);f.useEffect(()=>{p.current&&(p.current.indeterminate=n||!1)},[n]);const h=f.useCallback(b=>{if(!p.current||o)return;b.preventDefault();const I=!p.current.checked;p.current.checked=I,typeof a=="function"&&a(I)},[o,a]),g=f.useCallback(b=>{!b.key.match(/enter|spacebar|\W{1}/i)||!p.current||(b.preventDefault(),h(b))},[a]),v=f.useMemo(()=>u||Ot(),[u]);return W.jsxs(Jf,{style:i,background:l,children:[W.jsx("input",{ref:p,type:"checkbox",tabIndex:-1,disabled:o,checked:s,"aria-checked":n?"mixed":s,"aria-disabled":o,"aria-describedby":r?`${v}_description`:void 0,id:v,...m}),n?W.jsx(kt,{onClick:h,onKeyDown:g,tabIndex:0,"aria-checked":"mixed","aria-disabled":o,background:l,...m,children:W.jsx(Zf,{})}):W.jsx(vt,{onClick:h,onKeyDown:g,tabIndex:0,"aria-checked":s,"aria-disabled":o,background:l,...m,children:W.jsx(Hf,{})}),e&&W.jsxs(Xf,{children:[W.jsxs(jf,{children:[e&&W.jsx($f,{onClick:h,bold:!0,htmlFor:v,"data-tip":c,"data-tip-disable":d,children:e}),t&&W.jsx(zf,{children:t})]}),r&&W.jsx(Uf,{id:`${v}_description`,children:r})]})]})},vt=S.span`
316
+ `,fs=({label:e,subtitle:t,description:r,indeterminate:n,onChange:a,style:i,disabled:o,checked:s,id:u,background:l,"data-tip":c,"data-tip-disable":d,...m})=>{const p=f.useRef(null),h=f.useMemo(()=>u||Ot(),[u]);f.useEffect(()=>{p.current&&(p.current.indeterminate=n||!1)},[n]);const g=f.useCallback(b=>{if(!p.current||o)return;b.preventDefault();const I=!p.current.checked;if(p.current.checked=I,typeof a=="function"){const C={...b,target:{...p.current,checked:I,id:h}};a(C,I)}},[o,h,a]),v=f.useCallback(b=>{!b.key.match(/enter|spacebar|\W{1}/i)||!p.current||(b.preventDefault(),g(b))},[a]);return W.jsxs(Jf,{style:i,background:l,children:[W.jsx("input",{ref:p,type:"checkbox",tabIndex:-1,disabled:o,checked:s,"aria-checked":n?"mixed":s,"aria-disabled":o,"aria-describedby":r?`${h}_description`:void 0,id:h,...m}),n?W.jsx(kt,{onClick:g,onKeyDown:v,tabIndex:0,"aria-checked":"mixed","aria-disabled":o,background:l,...m,children:W.jsx(Zf,{})}):W.jsx(vt,{onClick:g,onKeyDown:v,tabIndex:0,"aria-checked":s,"aria-disabled":o,background:l,...m,children:W.jsx(Hf,{})}),e&&W.jsxs(Xf,{children:[W.jsxs(jf,{children:[e&&W.jsx($f,{onClick:g,bold:!0,htmlFor:h,"data-tip":c,"data-tip-disable":d,children:e}),t&&W.jsx(zf,{children:t})]}),r&&W.jsx(Uf,{id:`${h}_description`,children:r})]})]})},vt=S.span`
317
+ box-sizing: content-box;
312
318
  cursor: pointer;
313
319
  height: 16px;
314
320
  width: 16px;
@@ -316,6 +322,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
316
322
  background-color: transparent;
317
323
  border: 2px solid ${({background:e})=>e||"var(--color-stroke)"};
318
324
  position: relative;
325
+ flex-shrink: 0;
319
326
 
320
327
  &:focus-visible {
321
328
  outline: 0;
@@ -392,9 +399,12 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
392
399
  background: var(--color-disabled-text-on-light);
393
400
  }
394
401
 
395
- input:disabled ~ div p {
396
- cursor: default;
397
- color: var(--color-disabled-text-on-light);
402
+ input:disabled ~ div {
403
+ p,
404
+ label {
405
+ cursor: default;
406
+ color: var(--color-disabled-text-on-light);
407
+ }
398
408
  }
399
409
 
400
410
  :hover {
@@ -410,7 +420,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
410
420
  ${({background:e})=>e||"var(--color-active-darken10)"};
411
421
  }
412
422
  }
413
- `,Qf=e=>e.map(t=>go(t)?{label:t,value:t}:t),Kf=e=>(t,r)=>{const n=e.findIndex(i=>i.value===t),a=e.findIndex(i=>i.value===r);return n-a},qf=e=>vo(e).map(({props:t})=>t),eh=e=>e.filter(({defaultChecked:t})=>t).map(({value:t})=>t),th="[CheckboxGroup] Both the `children` and `options` props have been used.\n The `options` prop will be ignored. To get rid of this warning, remove one of these props.",nh="[CheckboxGroup] Both the `defaultChecked` and `defaultValue` props have been used.\n The `defaultValue` prop will be ignored. To get rid of this warning, remove one of these props.",rh=({value:e,disabled:t,name:r,children:n,className:a,options:i,onChange:o,defaultValue:s})=>{ca(n&&i,th);const u=f.useMemo(()=>n?qf(n):Qf(i||[]),[n,i]),l=f.useMemo(()=>{const h=eh(u),g=!!h.length;return g&&s&&la(nh),g?h:s},[u,s]),[c,d]=f.useState(e||l||[]);f.useEffect(()=>{e&&d(e)},[e]);const m=h=>c.includes(h),p=(h,g)=>{h.onChange&&h.onChange(g);const b=(g?[...c,h.value]:c.filter(I=>I!==h.value)).sort(Kf(u));d(b),o&&o(b)};return W.jsx(ah,{className:a,children:u.map(h=>W.jsx("li",{children:W.jsx(fs,{label:h.label,background:h.background,name:r,disabled:h.disabled||t||!1,checked:m(h.value),onChange:g=>p(h,g)})},h.value))})},ah=S.ul`
423
+ `,Qf=e=>e.map(t=>go(t)?{label:t,value:t}:t),Kf=e=>(t,r)=>{const n=e.findIndex(i=>i.value===t),a=e.findIndex(i=>i.value===r);return n-a},qf=e=>vo(e).map(({props:t})=>t),eh=e=>e.filter(({defaultChecked:t})=>t).map(({value:t})=>t),th="[CheckboxGroup] Both the `children` and `options` props have been used.\n The `options` prop will be ignored. To get rid of this warning, remove one of these props.",nh="[CheckboxGroup] Both the `defaultChecked` and `defaultValue` props have been used.\n The `defaultValue` prop will be ignored. To get rid of this warning, remove one of these props.",rh=({value:e,disabled:t,name:r,children:n,className:a,options:i,onChange:o,defaultValue:s})=>{ca(n&&i,th);const u=f.useMemo(()=>n?qf(n):Qf(i||[]),[n,i]),l=f.useMemo(()=>{const h=eh(u),g=!!h.length;return g&&s&&la(nh),g?h:s},[u,s]),[c,d]=f.useState(e||l||[]);f.useEffect(()=>{e&&d(e)},[e]);const m=h=>c.includes(h),p=(h,g,v)=>{h.onChange&&h.onChange(g,v);const I=(v?[...c,h.value]:c.filter(C=>C!==h.value)).sort(Kf(u));d(I),o&&o(I)};return W.jsx(ah,{className:a,children:u.map(h=>W.jsx("li",{children:W.jsx(fs,{label:h.label,background:h.background,name:r,disabled:h.disabled||t||!1,checked:m(h.value),onChange:(g,v)=>p(h,g,v)})},h.value))})},ah=S.ul`
414
424
  list-style: none;
415
425
  display: flex;
416
426
  flex-direction: column;
@@ -419,7 +429,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
419
429
  padding-inline-start: 0;
420
430
  padding-inline-end: 0;
421
431
  padding-block-start: 0;
422
- `,Oa=({label:e,subtitle:t,description:r,background:n,id:a,...i})=>{const[o]=f.useState(()=>a||`radio_${Ot()}`);return W.jsxs(ch,{background:n,children:[W.jsx("input",{type:"radio","aria-describedby":r?`${o}_description`:void 0,...i,id:o}),W.jsx(on,{background:n}),e&&W.jsxs(ih,{children:[W.jsxs(oh,{children:[e&&W.jsx(lh,{bold:!0,htmlFor:o,"data-tip":i["data-tip"],"data-tip-disable":i["data-tip-disable"],children:e}),t&&W.jsx(sh,{children:t})]}),r&&W.jsx(uh,{id:`${o}_description`,children:r})]})]})};Oa.propTypes={label:P.node,subtitle:P.node,description:P.node};Oa.defaultProps={label:null};const on=S.span`
432
+ `,Oa=({label:e,subtitle:t,description:r,background:n,id:a,onChange:i,...o})=>{const[s]=f.useState(()=>a||`radio_${Ot()}`),u=f.useCallback(c=>{if(o.disabled)return;c.preventDefault();const d={...c,target:{...c.target,checked:!0,id:s}};typeof i=="function"&&i(d,!0)},[s,i,o.disabled]),l=f.useCallback(c=>{c.key.match(/enter|spacebar|\W{1}/i)&&(c.preventDefault(),u(c))},[u]);return W.jsxs(ch,{background:n,children:[W.jsx("input",{type:"radio","aria-describedby":r?`${s}_description`:void 0,...o,id:s,onKeyDown:l}),W.jsx(on,{onClick:u,onKeyDown:l,background:n}),e&&W.jsxs(ih,{children:[W.jsxs(oh,{children:[e&&W.jsx(lh,{bold:!0,htmlFor:s,"data-tip":o["data-tip"],"data-tip-disable":o["data-tip-disable"],onClick:u,children:e}),t&&W.jsx(sh,{children:t})]}),r&&W.jsx(uh,{id:`${s}_description`,children:r})]})]})};Oa.propTypes={label:P.node,subtitle:P.node,description:P.node};Oa.defaultProps={label:null};const on=S.span`
423
433
  position: relative;
424
434
  height: 16px;
425
435
  width: 16px;
@@ -427,6 +437,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
427
437
  border: 2px solid ${({background:e})=>e||"var(--color-stroke)"};
428
438
  border-radius: var(--radius-circle);
429
439
  flex-shrink: 0;
440
+ cursor: pointer;
430
441
  input:focus + & {
431
442
  :before {
432
443
  content: "";