first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
import * as React from 'react';
export interface IControlledStateOptions<TProps, TProp extends keyof TProps, TDefaultProp extends keyof TProps> {
defaultPropValue?: TProps[TProp];
defaultPropName?: TDefaultProp;
}
/**
* Controlled state helper that gives priority to props value. Useful for components that have props with both
* controlled and uncontrolled modes. Any props values will override state, but will not update internal state.
* If prop is defined and then later undefined, state will revert to its previous value.
*
* @param props - The props object containing controlled prop values.
* @param propName - The controlled prop name.
* @param options - Options. defaultPropValue is only used if defaultPropName (or its value) is undefined.
*/
export declare function useControlledState<TProps, TProp extends keyof TProps, TDefaultProp extends keyof TProps>(props: Readonly<TProps>, propName: TProp, options?: IControlledStateOptions<TProps, TProp, TDefaultProp>): [TProps[TProp] | undefined, React.Dispatch<React.SetStateAction<TProps[TProp]>>];
/**
* Simple controlled helper that gives priority to props value and falls back to derived value.
*
* @param props - The props object containing controlled prop values.
* @param propName - The controlled prop name.
* @param derivedValue - Derived value. Returned when controlled value is not present.
*/
export declare function getControlledDerivedProps<TProps, TProp extends keyof TProps>(props: Readonly<TProps>, propName: TProp, derivedValue: TProps[TProp]): TProps[TProp];
+45
View File
@@ -0,0 +1,45 @@
import * as React from 'react';
/**
* Controlled state helper that gives priority to props value. Useful for components that have props with both
* controlled and uncontrolled modes. Any props values will override state, but will not update internal state.
* If prop is defined and then later undefined, state will revert to its previous value.
*
* @param props - The props object containing controlled prop values.
* @param propName - The controlled prop name.
* @param options - Options. defaultPropValue is only used if defaultPropName (or its value) is undefined.
*/
export function useControlledState(props, propName, options) {
var defaultValue;
if (options) {
if (options.defaultPropName && props[options.defaultPropName] !== undefined) {
// No easy way to coerce TProps[TDefaultProp] to match TProps[TProp] in generic typings, so cast it here.
defaultValue = props[options.defaultPropName];
}
else {
defaultValue = options && options.defaultPropValue;
}
}
var _a = React.useState(defaultValue), state = _a[0], setState = _a[1];
if (props[propName] !== undefined) {
return [props[propName], setState];
}
else {
return [state, setState];
}
}
/**
* Simple controlled helper that gives priority to props value and falls back to derived value.
*
* @param props - The props object containing controlled prop values.
* @param propName - The controlled prop name.
* @param derivedValue - Derived value. Returned when controlled value is not present.
*/
export function getControlledDerivedProps(props, propName, derivedValue) {
if (props[propName] !== undefined) {
return props[propName];
}
else {
return derivedValue;
}
}
//# sourceMappingURL=controlled.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"controlled.js","sourceRoot":"../src/","sources":["hooks/controlled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAuB,EACvB,QAAe,EACf,OAA8D;IAE9D,IAAI,YAAuC,CAAC;IAC5C,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,SAAS,EAAE,CAAC;YAC5E,yGAAyG;YACzG,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,CAA6B,CAAC;QAC5E,CAAC;aAAM,CAAC;YACN,YAAY,GAAG,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;QACrD,CAAC;IACH,CAAC;IAEK,IAAA,KAAoB,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,EAA/C,KAAK,QAAA,EAAE,QAAQ,QAAgC,CAAC;IAEvD,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAuB,EACvB,QAAe,EACf,YAA2B;IAE3B,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,YAAY,CAAC;IACtB,CAAC;AACH,CAAC","sourcesContent":["import * as React from 'react';\n\nexport interface IControlledStateOptions<TProps, TProp extends keyof TProps, TDefaultProp extends keyof TProps> {\n defaultPropValue?: TProps[TProp];\n defaultPropName?: TDefaultProp;\n}\n\n/**\n * Controlled state helper that gives priority to props value. Useful for components that have props with both\n * controlled and uncontrolled modes. Any props values will override state, but will not update internal state.\n * If prop is defined and then later undefined, state will revert to its previous value.\n *\n * @param props - The props object containing controlled prop values.\n * @param propName - The controlled prop name.\n * @param options - Options. defaultPropValue is only used if defaultPropName (or its value) is undefined.\n */\nexport function useControlledState<TProps, TProp extends keyof TProps, TDefaultProp extends keyof TProps>(\n props: Readonly<TProps>,\n propName: TProp,\n options?: IControlledStateOptions<TProps, TProp, TDefaultProp>,\n): [TProps[TProp] | undefined, React.Dispatch<React.SetStateAction<TProps[TProp]>>] {\n let defaultValue: TProps[TProp] | undefined;\n if (options) {\n if (options.defaultPropName && props[options.defaultPropName] !== undefined) {\n // No easy way to coerce TProps[TDefaultProp] to match TProps[TProp] in generic typings, so cast it here.\n defaultValue = props[options.defaultPropName] as unknown as TProps[TProp];\n } else {\n defaultValue = options && options.defaultPropValue;\n }\n }\n\n const [state, setState] = React.useState(defaultValue);\n\n if (props[propName] !== undefined) {\n return [props[propName], setState];\n } else {\n return [state, setState];\n }\n}\n\n/**\n * Simple controlled helper that gives priority to props value and falls back to derived value.\n *\n * @param props - The props object containing controlled prop values.\n * @param propName - The controlled prop name.\n * @param derivedValue - Derived value. Returned when controlled value is not present.\n */\nexport function getControlledDerivedProps<TProps, TProp extends keyof TProps>(\n props: Readonly<TProps>,\n propName: TProp,\n derivedValue: TProps[TProp],\n): TProps[TProp] {\n if (props[propName] !== undefined) {\n return props[propName];\n } else {\n return derivedValue;\n }\n}\n"]}
+1
View File
@@ -0,0 +1 @@
export * from './controlled';
+2
View File
@@ -0,0 +1,2 @@
export * from './controlled';
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC","sourcesContent":["export * from './controlled';\n"]}