@kwiz/fluentui 1.0.153 → 1.0.154

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.
Files changed (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +53 -53
  3. package/dist/@types/forwardRef.d.ts +0 -0
  4. package/dist/@types/forwardRef.js +1 -0
  5. package/dist/@types/forwardRef.js.map +1 -0
  6. package/dist/_modules/config.d.ts +1 -0
  7. package/dist/_modules/config.js +9 -0
  8. package/dist/_modules/config.js.map +1 -0
  9. package/dist/_modules/constants.d.ts +2 -0
  10. package/dist/_modules/constants.js +3 -0
  11. package/dist/_modules/constants.js.map +1 -0
  12. package/dist/controls/combobox.d.ts +12 -0
  13. package/dist/controls/combobox.js +21 -0
  14. package/dist/controls/combobox.js.map +1 -0
  15. package/dist/controls/date copy.d.ts +14 -0
  16. package/dist/controls/date copy.js +49 -0
  17. package/dist/controls/date copy.js.map +1 -0
  18. package/dist/controls/error-boundary copy.d.ts +23 -0
  19. package/dist/controls/error-boundary copy.js +33 -0
  20. package/dist/controls/error-boundary copy.js.map +1 -0
  21. package/dist/controls/field.d.ts +11 -0
  22. package/dist/controls/field.js +33 -0
  23. package/dist/controls/field.js.map +1 -0
  24. package/dist/controls/form-context.d.ts +20 -0
  25. package/dist/controls/form-context.js +50 -0
  26. package/dist/controls/form-context.js.map +1 -0
  27. package/dist/controls/form.d.ts +29 -0
  28. package/dist/controls/form.js +58 -0
  29. package/dist/controls/form.js.map +1 -0
  30. package/dist/controls/index.d.ts +4 -0
  31. package/dist/controls/index.js +4 -0
  32. package/dist/controls/index.js.map +1 -1
  33. package/dist/controls/kwizoverflow copy.d.ts +14 -0
  34. package/dist/controls/kwizoverflow copy.js +47 -0
  35. package/dist/controls/kwizoverflow copy.js.map +1 -0
  36. package/dist/controls/svg.js +21 -21
  37. package/dist/controls/svg.js.map +1 -1
  38. package/dist/controls/table.d.ts +42 -0
  39. package/dist/controls/table.js +139 -0
  40. package/dist/controls/table.js.map +1 -0
  41. package/dist/controls/vertical.d.ts +1 -3
  42. package/dist/helpers/common.d.ts +4 -0
  43. package/dist/helpers/common.js +2 -0
  44. package/dist/helpers/common.js.map +1 -0
  45. package/dist/helpers/context.d.ts +26 -0
  46. package/dist/helpers/context.js +15 -0
  47. package/dist/helpers/context.js.map +1 -0
  48. package/dist/helpers/drag-drop/exports.d.ts +12 -0
  49. package/dist/helpers/drag-drop/exports.js +3 -0
  50. package/dist/helpers/drag-drop/exports.js.map +1 -0
  51. package/dist/helpers/exports.d.ts +7 -0
  52. package/dist/helpers/exports.js +8 -0
  53. package/dist/helpers/exports.js.map +1 -0
  54. package/dist/helpers/use-highlight.js +8 -8
  55. package/package.json +88 -88
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 KWIZ Corp
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 KWIZ Corp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,53 +1,53 @@
1
- # fluentui
2
-
3
- For local debugging, if you plan to use `npm link` - there is a known issue with react that will potentially break your application.
4
-
5
- To fix that, you must mark react and fluentui imports as external.
6
- The best way of doing it is using webpack to build your app, and adding this:
7
- ```json
8
- resolve: {
9
- ...
10
- modules: [path.resolve(__dirname, 'node_modules'), 'node_modules']//important! needed for @kwiz/fluentui to work correctly when linked
11
- }
12
- ```
13
-
14
- Otherwise during dev, you'll have to link the react package in this project to load the react from node_modules in your caller application. For example:
15
-
16
- ```
17
- npm link ..\\test-project\\node_modules\\react\\ ..\\..test-project\\node_modules\\@types\\react\\
18
- ```
19
-
20
- To successfully use these controls you should create a context, and wrapt it in a drag/drop provider.
21
-
22
- We recommend using the provider control:
23
-
24
- ```ts
25
- <KWIZFluentProvider ctx={{ buttonShape: "rounded" }}>
26
- <FluentProvider theme={webLightTheme}>
27
- {content}
28
- </FluentProvider>
29
- </KWIZFluentProvider>
30
-
31
- ```
32
-
33
- Or you can use the following code:
34
-
35
- ```ts
36
- // it is no longer needed to send in a root node const root = React.useRef<HTMLDivElement>(null);
37
- const { KWIZFluentContext, value: kwizFluentContext } =
38
- useKWIZFluentContextProvider({
39
- ctx: {
40
- buttonShape: "rounded",
41
- },
42
- //root,
43
- });
44
-
45
- //...
46
- <KWIZFluentContext.Provider value={kwizFluentContext}>
47
- <DragDropContextProvider>
48
- <FluentProvider theme={webLightTheme} /*ref={root}*/>
49
- {content}
50
- </FluentProvider>
51
- </DragDropContextProvider>
52
- </KWIZFluentContext.Provider>;
53
- ```
1
+ # fluentui
2
+
3
+ For local debugging, if you plan to use `npm link` - there is a known issue with react that will potentially break your application.
4
+
5
+ To fix that, you must mark react and fluentui imports as external.
6
+ The best way of doing it is using webpack to build your app, and adding this:
7
+ ```json
8
+ resolve: {
9
+ ...
10
+ modules: [path.resolve(__dirname, 'node_modules'), 'node_modules']//important! needed for @kwiz/fluentui to work correctly when linked
11
+ }
12
+ ```
13
+
14
+ Otherwise during dev, you'll have to link the react package in this project to load the react from node_modules in your caller application. For example:
15
+
16
+ ```
17
+ npm link ..\\test-project\\node_modules\\react\\ ..\\..test-project\\node_modules\\@types\\react\\
18
+ ```
19
+
20
+ To successfully use these controls you should create a context, and wrapt it in a drag/drop provider.
21
+
22
+ We recommend using the provider control:
23
+
24
+ ```ts
25
+ <KWIZFluentProvider ctx={{ buttonShape: "rounded" }}>
26
+ <FluentProvider theme={webLightTheme}>
27
+ {content}
28
+ </FluentProvider>
29
+ </KWIZFluentProvider>
30
+
31
+ ```
32
+
33
+ Or you can use the following code:
34
+
35
+ ```ts
36
+ // it is no longer needed to send in a root node const root = React.useRef<HTMLDivElement>(null);
37
+ const { KWIZFluentContext, value: kwizFluentContext } =
38
+ useKWIZFluentContextProvider({
39
+ ctx: {
40
+ buttonShape: "rounded",
41
+ },
42
+ //root,
43
+ });
44
+
45
+ //...
46
+ <KWIZFluentContext.Provider value={kwizFluentContext}>
47
+ <DragDropContextProvider>
48
+ <FluentProvider theme={webLightTheme} /*ref={root}*/>
49
+ {content}
50
+ </FluentProvider>
51
+ </DragDropContextProvider>
52
+ </KWIZFluentContext.Provider>;
53
+ ```
File without changes
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=forwardRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forwardRef.js","sourceRoot":"","sources":["../../src/@types/forwardRef.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare const GetLogger: (name: string) => import("@kwiz/common").ConsoleLogger;
@@ -0,0 +1,9 @@
1
+ import { config } from "@kwiz/common";
2
+ import { BuildNumber, ReleaseStatus } from "./constants";
3
+ export const { logger: GetLogger } = config({
4
+ BuildNumber: BuildNumber,
5
+ IsLocalDev: false,
6
+ ReleaseStatus: ReleaseStatus,
7
+ ProjectName: "[fluentui]"
8
+ });
9
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/_modules/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IACxC,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,aAAa;IAC5B,WAAW,EAAE,YAAY;CAC5B,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare var BuildNumber: string;
2
+ export declare const ReleaseStatus = "npm";
@@ -0,0 +1,3 @@
1
+ export var BuildNumber = 'unset';
2
+ export const ReleaseStatus = "npm";
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/_modules/constants.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,IAAI,WAAW,GAAG,OAAO,CAAC;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { ComboboxProps } from "@fluentui/react-components";
2
+ interface iProps extends Omit<ComboboxProps, "selectedOptions" | "onChange" | "onOptionSelect" | "children"> {
3
+ items: {
4
+ key: string;
5
+ text: string;
6
+ }[];
7
+ value: string;
8
+ onChange: (value: string) => void;
9
+ freeFormPrefix?: string;
10
+ }
11
+ export declare function ComboboxEX(props: iProps): import("react/jsx-runtime").JSX.Element;
12
+ export {};
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Combobox, Option } from "@fluentui/react-components";
3
+ import { firstOrNull, isNotEmptyString } from "@kwiz/common";
4
+ import { useMemo } from "react";
5
+ const freeFormKey = "$freeform";
6
+ //** a controlled single select combo box that allows custom text typing */
7
+ export function ComboboxEX(props) {
8
+ const { items, value, onChange, freeFormPrefix } = props;
9
+ const selectedOption = useMemo(() => firstOrNull(items, i => i.key === value), [items, value]);
10
+ const text = (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.text) || value;
11
+ return _jsxs(Combobox, Object.assign({}, props, { value: text, selectedOptions: isNotEmptyString(value) ? [selectedOption ? selectedOption.key : freeFormKey] : [], onChange: (e) => {
12
+ console.log(e.currentTarget.value);
13
+ onChange(e.currentTarget.value);
14
+ }, onOptionSelect: (e, data) => {
15
+ if (isNotEmptyString(data.optionValue)) {
16
+ console.log(data.optionValue);
17
+ onChange(data.optionValue);
18
+ }
19
+ }, children: [!selectedOption && _jsx(Option, { children: `${freeFormPrefix}${value}` }, freeFormKey), items.map(o => _jsx(Option, { value: o.key, children: o.text }, o.key))] }));
20
+ }
21
+ //# sourceMappingURL=combobox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combobox.js","sourceRoot":"","sources":["../../src/controls/combobox.tsx"],"names":[],"mappings":";AAAA,OAAO,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AC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/B,CAAC;QACL,CAAC,aACA,CAAC,cAAc,IAAI,KAAC,MAAM,cAAoB,GAAG,cAAc,GAAG,KAAK,EAAE,IAAzC,WAAW,CAAwC,EACnF,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAC,MAAM,IAAa,KAAK,EAAE,CAAC,CAAC,GAAG,YAAG,CAAC,CAAC,IAAI,IAA5B,CAAC,CAAC,GAAG,CAAiC,CAAC,KAC7D,CAAC;AAChB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { DatePickerProps } from '@fluentui/react-datepicker-compat';
2
+ import { TimePickerProps } from '@fluentui/react-timepicker-compat';
3
+ import * as React from 'react';
4
+ interface IProps {
5
+ onDateChange: (newDateObject: Date) => void;
6
+ value: Date;
7
+ showTime?: boolean;
8
+ datePickerProps?: DatePickerProps;
9
+ timePickerProps?: TimePickerProps;
10
+ /** don't allow to clear the value */
11
+ required?: boolean;
12
+ }
13
+ export declare const DatePickerEx: React.FunctionComponent<React.PropsWithChildren<IProps>>;
14
+ export {};
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { DatePicker } from '@fluentui/react-datepicker-compat';
3
+ import { TimePicker } from '@fluentui/react-timepicker-compat';
4
+ import { CalendarCancelRegular } from '@fluentui/react-icons';
5
+ import { isDate } from '@kwiz/common';
6
+ import * as React from 'react';
7
+ import { useKWIZFluentContext } from '../helpers/context-internal';
8
+ import { useStateEX } from '../helpers';
9
+ import { Horizontal } from './horizontal';
10
+ export const DatePickerEx = (props) => {
11
+ const ctx = useKWIZFluentContext();
12
+ //time value will always have a value even when clearing the date
13
+ const [timeValue, setTimeValue] = useStateEX(isDate(props.value) ? props.value : new Date());
14
+ const { showClear, dateValue } = React.useMemo(() => {
15
+ const showClear = !props.required && isDate(props.value);
16
+ const dateValue = props.value;
17
+ return { showClear, dateValue };
18
+ }, [props.value]);
19
+ function reset() {
20
+ props.onDateChange(null);
21
+ }
22
+ const changeDateHandler = React.useCallback((newDateValue) => {
23
+ const newDate = new Date(newDateValue);
24
+ // Use the old time values.
25
+ newDate.setHours(timeValue ? timeValue.getHours() : 0, timeValue ? timeValue.getMinutes() : 0, 0, 0);
26
+ props.onDateChange(newDate);
27
+ }, [timeValue, props.onDateChange]);
28
+ const changeTimeHandler = React.useCallback((newTimeValue) => {
29
+ //update our state
30
+ setTimeValue(newTimeValue);
31
+ // Use the old date value.
32
+ const newDate = isDate(dateValue) ? new Date(dateValue) : new Date();
33
+ newDate.setHours(newTimeValue.getHours(), newTimeValue.getMinutes(), 0, 0);
34
+ props.onDateChange(newDate);
35
+ }, [dateValue]);
36
+ const DatePickerControl = _jsx(DatePicker, Object.assign({}, (props.datePickerProps || {}), { appearance: ctx.inputAppearance, mountNode: ctx.mountNode, value: isDate(dateValue) ? dateValue : null, onSelectDate: (newDate) => {
37
+ changeDateHandler(newDate);
38
+ }, contentBefore: showClear && _jsx(CalendarCancelRegular, { title: 'Clear', onClick: () => reset() }) }));
39
+ const TimePickerControl = _jsx(TimePicker, Object.assign({ appearance: ctx.inputAppearance, mountNode: ctx.mountNode }, props.timePickerProps, {
40
+ //only show time value when there is a selected date. timeValue will never be null.
41
+ value: isDate(dateValue) ? timeValue.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hour12: true }) : "", onTimeChange: (e, date) => {
42
+ const newDate = date.selectedTime;
43
+ changeTimeHandler(newDate);
44
+ } }));
45
+ return (props.showTime
46
+ ? _jsxs(Horizontal, { children: [DatePickerControl, TimePickerControl] })
47
+ : DatePickerControl);
48
+ };
49
+ //# sourceMappingURL=date%20copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date copy.js","sourceRoot":"","sources":["../../src/controls/date copy.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,UAAU,EAAmB,MAAM,mCAAm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,CAAC,KAAK,EAAE,GAAI,IAC7F,CAAA;IAEF,MAAM,iBAAiB,GAAG,KAAC,UAAU,kBACjC,UAAU,EAAE,GAAG,CAAC,eAAe,EAC/B,SAAS,EAAE,GAAG,CAAC,SAAS,IACpB,KAAK,CAAC,eAAe;QACzB,mFAAmF;QACnF,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EACxH,YAAY,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;YACtB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC;YAClC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC,IACH,CAAA;IAEF,OAAO,CACH,KAAK,CAAC,QAAQ;QACV,CAAC,CAAC,MAAC,UAAU,eACR,iBAAiB,EACjB,iBAAiB,IACT;QACb,CAAC,CAAC,iBAAiB,CAC1B,CAAC;AACN,CAAC,CAAA"}
@@ -0,0 +1,23 @@
1
+ import React, { PropsWithChildren } from "react";
2
+ interface iProps {
3
+ errorComponent?: JSX.Element;
4
+ /** If changeMarker changes, it will check the error again */
5
+ changeMarker: string | number;
6
+ }
7
+ interface iState {
8
+ hasError: boolean;
9
+ marker: string | number;
10
+ }
11
+ export declare class ErrorBoundary extends React.Component<PropsWithChildren<iProps>, iState> {
12
+ constructor(props: iProps);
13
+ static getDerivedStateFromError(error: any): {
14
+ hasError: boolean;
15
+ };
16
+ static getDerivedStateFromProps(props: iProps, state: iState): {
17
+ hasError: boolean;
18
+ marker: string | number;
19
+ };
20
+ componentDidCatch(error: any, errorInfo: any): void;
21
+ render(): string | number | boolean | Iterable<React.ReactNode> | JSX.Element;
22
+ }
23
+ export {};
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { GetLogger } from "_modules";
3
+ import React from "react";
4
+ const logger = GetLogger("ErrorBoundary");
5
+ export class ErrorBoundary extends React.Component {
6
+ constructor(props) {
7
+ super(props);
8
+ this.state = { hasError: false, marker: props.changeMarker };
9
+ }
10
+ static getDerivedStateFromError(error) {
11
+ // Update state so the next render will show the fallback UI.
12
+ return { hasError: true };
13
+ }
14
+ static getDerivedStateFromProps(props, state) {
15
+ if (props.changeMarker !== state.marker)
16
+ return { hasError: false, marker: props.changeMarker };
17
+ else
18
+ return null;
19
+ }
20
+ componentDidCatch(error, errorInfo) {
21
+ // You can also log the error to an error reporting service
22
+ logger.error(error);
23
+ logger.error(errorInfo);
24
+ }
25
+ render() {
26
+ if (this.state.hasError) {
27
+ // You can render any custom fallback UI
28
+ return this.props.errorComponent || _jsx("h1", { children: "Something went wrong." });
29
+ }
30
+ return this.props.children;
31
+ }
32
+ }
33
+ //# sourceMappingURL=error-boundary%20copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary copy.js","sourceRoot":"","sources":["../../src/controls/error-boundary copy.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,KAA4B,MAAM,OAAO,CAAC;AAEjD,MAAM,MAAM,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;AAQ1C,MAAM,OAAO,aAAc,SAAQ,KAAK,CAAC,SAA4C;IACjF,YAAY,KAAa;QACrB,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;IACjE,CAAC;IAED,MAAM,CAAC,wBAAwB,CAAC,KAAK;QACjC,6DAA6D;QAC7D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;IACD,MAAM,CAAC,wBAAwB,CAAC,KAAa,EAAE,KAAa;QACxD,IAAI,KAAK,CAAC,YAAY,KAAK,KAAK,CAAC,MAAM;YACnC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;;YACtD,OAAO,IAAI,CAAC;IACrB,CAAC;IAED,iBAAiB,CAAC,KAAK,EAAE,SAAS;QAC9B,2DAA2D;QAC3D,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpB,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM;QACF,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACtB,wCAAwC;YACxC,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,IAAI,iDAA8B,CAAC;QACvE,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC/B,CAAC;CACJ"}
@@ -0,0 +1,11 @@
1
+ import { FieldProps } from "@fluentui/react-components";
2
+ interface iProps<ValueType> extends FieldProps {
3
+ /** return non empty string if value is not valid */
4
+ validation?: () => string;
5
+ formKey?: string;
6
+ required?: boolean;
7
+ /** sendIn */
8
+ value?: ValueType;
9
+ }
10
+ export declare function FormFieldEX<ValueType>(props: iProps<ValueType>): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Field } from "@fluentui/react-components";
3
+ import { isNotEmptyString, isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, stringEqualsOrEmpty } from "@kwiz/common";
4
+ import { useCallback, useEffect, useState } from "react";
5
+ import { useFormValidationContext } from "./form-context";
6
+ export function FormFieldEX(props) {
7
+ const { validation, formKey, required, value } = props;
8
+ const validate_internal = useCallback(() => {
9
+ //calc if value is valid
10
+ let error = validation
11
+ ? validation()
12
+ : "";
13
+ if (isNullOrEmptyString(error) && required) {
14
+ if ((Array.isArray(value) ? isNullOrEmptyArray(value) : isNullOrEmptyString(value)))
15
+ error = "Missing required value";
16
+ }
17
+ return error;
18
+ }, [validation, required, value]);
19
+ const [error, setError] = useState(validate_internal());
20
+ useEffect(() => {
21
+ const newError = validate_internal();
22
+ if (!stringEqualsOrEmpty(newError, error))
23
+ setError(newError);
24
+ }, [validate_internal, value, error]);
25
+ const formContext = useFormValidationContext();
26
+ useEffect(() => {
27
+ if (!isNullOrUndefined(formContext === null || formContext === void 0 ? void 0 : formContext.setError)) {
28
+ formContext.setError(error, formKey);
29
+ }
30
+ }, [formContext, error, formKey]);
31
+ return _jsx(Field, Object.assign({}, props, { validationMessage: formContext.showErrors ? error : undefined, validationState: formContext.showErrors && isNotEmptyString(error) ? "error" : "none", children: props.children }));
32
+ }
33
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/controls/field.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjI,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAY1D,MAAM,UAAU,WAAW,CAAY,KAAwB;IAC3D,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAEvD,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,EAAE;QACvC,wBAAwB;QACxB,IAAI,KAAK,GAAG,UAAU;YAClB,CAAC,CAAC,UAAU,EAAE;YACd,CAAC,CAAC,EAAE,CAAC;QACT,IAAI,mBAAmB,CAAC,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;YACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,K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iz/common";
2
+ import React, { ReactNode } from "react";
3
+ /** do not add to index - this is to be used in FormDialogEX
4
+ * we should create anotehr wrapper for forms that do not need a dialog (toolbar? save/cancel action?)
5
+ */
6
+ interface iFormValidationContext {
7
+ errors?: IDictionary<string>;
8
+ setError?: (error: string, key?: string) => void;
9
+ showErrors?: boolean;
10
+ }
11
+ export declare const FormValidationContext: React.Context<iFormValidationContext>;
12
+ /** fields inside a FormEX component can react to validation errors */
13
+ export declare function useFormValidationContext(): iFormValidationContext;
14
+ /** Creates a form validation context, reports back if form is valid so you can enable/disable the save button */
15
+ export declare function Internal_FormEX({ children, onValid, submitError }: {
16
+ children: ReactNode;
17
+ onValid?: (isValid: boolean) => void;
18
+ submitError?: string;
19
+ }): import("react/jsx-runtime").JSX.Element;
20
+ export {};
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { MessageBar } from "@fluentui/react-components";
3
+ import { isNotEmptyString, isNullOrEmptyString, jsonClone, stringEqualsOrEmpty } from "@kwiz/common";
4
+ import React, { useCallback, useEffect, useState } from "react";
5
+ //create context
6
+ export const FormValidationContext = React.createContext({});
7
+ /** fields inside a FormEX component can react to validation errors */
8
+ export function useFormValidationContext() {
9
+ const ctx = React.useContext(FormValidationContext);
10
+ return ctx;
11
+ }
12
+ /** Creates a form validation context, reports back if form is valid so you can enable/disable the save button */
13
+ export function Internal_FormEX({ children, onValid, submitError }) {
14
+ const [showErrors, setShowErrors] = useState(false);
15
+ const [errors, setErrors] = useState({});
16
+ useEffect(() => {
17
+ let valid = true;
18
+ Object.values(errors).forEach(value => {
19
+ if (isNotEmptyString(value))
20
+ valid = false;
21
+ });
22
+ onValid === null || onValid === void 0 ? void 0 : onValid(valid);
23
+ }, [errors, onValid]);
24
+ const setError = useCallback((error, key) => {
25
+ //clear form errors on any other field change...
26
+ let clearFormError = isNotEmptyString(key);
27
+ key = isNullOrEmptyString(key) ? "form" : key;
28
+ //current error
29
+ const currentError = errors[key];
30
+ if (!stringEqualsOrEmpty(currentError, error)) {
31
+ clearFormError = clearFormError && isNullOrEmptyString(error);
32
+ const newErrors = jsonClone(errors);
33
+ if (clearFormError)
34
+ delete newErrors.form;
35
+ newErrors[key] = error;
36
+ //report back to a form errors collection
37
+ setErrors(newErrors);
38
+ }
39
+ }, [errors]);
40
+ useEffect(() => {
41
+ if (!showErrors && isNotEmptyString(submitError))
42
+ setShowErrors(true);
43
+ }, [submitError, showErrors]);
44
+ return _jsxs(FormValidationContext.Provider, { value: {
45
+ errors,
46
+ setError,
47
+ showErrors
48
+ }, children: [isNotEmptyString(submitError) && _jsx(MessageBar, { intent: "error", children: submitError }), isNotEmptyString(errors.form) && _jsx(MessageBar, { intent: "error", children: errors.form }), children] });
49
+ }
50
+ //# sourceMappingURL=form-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-context.js","sourceRoot":"","sources":["../../src/controls/form-context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAe,gBAAgB,EAAE,mBAAmB,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAClH,OAAO,KAAK,EAAE,EAAa,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAa3E,gBAAgB;AAChB,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC,aAAa,CAAyB,EAAE,CAAC,CAAC;AACrF,sEAAsE;AACtE,MAAM,UAAU,wBAAwB;IACpC,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;IACpD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAI/D;IACG,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;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AAC;YAAE,aAAa,CAAC,IAAI,CAAC,CAAC;IAC1E,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;IAE9B,OAAO,MAAC,qBAAqB,CAAC,QAAQ,IAClC,KAAK,EAAE;YACH,MAAM;YACN,QAAQ;YACR,UAAU;SACb,aACA,gBAAgB,CAAC,WAAW,CAAC,IAAI,KAAC,UAAU,IAAC,MAAM,EAAC,OAAO,YAAE,WAAW,GAAc,EACtF,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAC,UAAU,IAAC,MAAM,EAAC,OAAO,YAAE,MAAM,CAAC,IAAI,GAAc,EACtF,QAAQ,IACoB,CAAC;AACtC,CAAC"}
@@ -0,0 +1,29 @@
1
+ /** T would be some sort of FormData {
2
+ * field:type1
3
+ * }
4
+ * > Make sure K is a key in FormData
5
+ * > Make sure the value type of that field value is type1 T[K]
6
+ * read more: https://stackoverflow.com/questions/68304361/how-to-define-an-array-of-generic-objects-in-typescript-each-item-having-a-diff
7
+ } */
8
+ type FormField<FormData> = {
9
+ [FieldName in keyof FormData]: {
10
+ required?: boolean;
11
+ label?: string;
12
+ hint?: string;
13
+ key: FieldName;
14
+ validation?: (value: FormData[FieldName], values: FormData) => string;
15
+ /** should not be an uncontrolled control */
16
+ fieldControl: (value: FormData[FieldName], setValue: (value: FormData[FieldName]) => void) => JSX.Element;
17
+ };
18
+ }[keyof FormData & string];
19
+ export declare function FormDialogEX<FormData>({ defaultValues, fields, buttonIcon, buttonTitle, dialogTitle, onSubmit, onClose }: {
20
+ defaultValues: FormData;
21
+ fields: FormField<FormData>[];
22
+ buttonIcon?: JSX.Element;
23
+ buttonTitle?: string;
24
+ dialogTitle: string;
25
+ /** called if form fields are all valid */
26
+ onSubmit: (values: FormData) => Promise<string>;
27
+ onClose?: () => void;
28
+ }): import("react/jsx-runtime").JSX.Element;
29
+ export {};
@@ -0,0 +1,58 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ import { MessageBar } from "@fluentui/react-components";
12
+ import { CommonConfig, isNotEmptyString, isNullOrUndefined, jsonClone } from "@kwiz/common";
13
+ import { useCallback, useState } from "react";
14
+ import { ButtonEXPrimarySubtle } from "./button";
15
+ import { FormFieldEX } from "./field";
16
+ import { Internal_FormEX } from "./form-context";
17
+ import { PleaseWait } from "./please-wait";
18
+ import { Prompter } from "./prompt";
19
+ import { Vertical } from "./vertical";
20
+ export function FormDialogEX({ defaultValues, fields, buttonIcon, buttonTitle, dialogTitle, onSubmit, onClose }) {
21
+ const addButton = !isNullOrUndefined(buttonIcon) || isNotEmptyString(buttonTitle);
22
+ const [inProgress, setInProgress] = useState(false);
23
+ const [show, setShow] = useState(false);
24
+ const [valid, setValid] = useState(false);
25
+ const [submitError, setSubmitError] = useState("");
26
+ const [values, setValues] = useState(defaultValues);
27
+ const clearForm = useCallback(() => {
28
+ setValid(false);
29
+ setSubmitError("");
30
+ setValues(jsonClone(defaultValues));
31
+ }, [defaultValues]);
32
+ return _jsxs(_Fragment, { children: [addButton && _jsx(ButtonEXPrimarySubtle, { icon: buttonIcon, title: buttonTitle, onClick: () => { clearForm(); setShow(true); } }), (show || !addButton) && _jsx(Prompter, { title: dialogTitle, onCancel: () => {
33
+ setShow(false);
34
+ onClose === null || onClose === void 0 ? void 0 : onClose();
35
+ }, okButtonProps: { disabled: !valid }, onOK: () => __awaiter(this, void 0, void 0, function* () {
36
+ if (valid) {
37
+ setInProgress(true);
38
+ let serverError = "";
39
+ try {
40
+ serverError = yield onSubmit(values);
41
+ }
42
+ catch (e) {
43
+ console.log(e);
44
+ serverError = "Unknown server error";
45
+ }
46
+ if (isNotEmptyString(serverError)) {
47
+ setSubmitError(serverError);
48
+ }
49
+ else {
50
+ setShow(false);
51
+ }
52
+ setInProgress(false);
53
+ }
54
+ }), children: _jsxs(Vertical, { children: [inProgress && _jsx(PleaseWait, {}), _jsx(Internal_FormEX, { submitError: submitError, onValid: isValid => setValid(isValid), children: fields.map(field => _jsxs(FormFieldEX, { label: field.label, hint: field.hint, formKey: field.key, required: field.required, value: values[field.key], validation: field.validation ? () => {
55
+ return field.validation(values[field.key], values);
56
+ } : undefined, children: [isNullOrUndefined(values[field.key]) && CommonConfig.i.IsLocalDev && _jsx(MessageBar, { layout: "multiline", intent: "warning", children: "This should be a controlled element, value should never be null or your control might get out of sync." }), field.fieldControl(values[field.key], newValue => setValues(Object.assign(Object.assign({}, values), { [field.key]: newValue })))] }, field.key)) })] }) })] });
57
+ }
58
+ //# sourceMappingURL=form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.js","sourceRoot":"","sources":["../../src/controls/form.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,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AAO,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;gCACvD,CAAC,CAAC,CAAC,CAAC,SAAS,aAEZ,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,UAAU,IAAI,KAAC,UAAU,IAAC,MAAM,EAAC,WAAW,EAAC,MAAM,EAAC,SAAS,uHAAoH,EACxO,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,SAAS,iCAAM,MAAM,KAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,QAAQ,IAAG,CAAC,KAPhE,KAAK,CAAC,GAAG,CAQlC,CAAC,GACD,IACX,GACJ,IACZ,CAAC;AACR,CAAC"}
@@ -6,15 +6,18 @@ export * from './card-list';
6
6
  export * from './centered';
7
7
  export * from './code-editor';
8
8
  export * from './ColorPickerDialog';
9
+ export * from './combobox';
9
10
  export * from './date';
10
11
  export * from './diagram-picker';
11
12
  export * from './divider';
12
13
  export * from './drawer-ex';
13
14
  export * from './dropdown';
14
15
  export * from './error-boundary';
16
+ export * from './field';
15
17
  export * from './field-editor';
16
18
  export * from './field-set';
17
19
  export * from './file-upload';
20
+ export * from './form';
18
21
  export * from './horizontal';
19
22
  export * from './html-editor';
20
23
  export * from './input';
@@ -33,6 +36,7 @@ export * from './search';
33
36
  export * from './section';
34
37
  export * from './stack';
35
38
  export * from './svg';
39
+ export * from './table';
36
40
  export * from './tabs';
37
41
  export * from './tag-ex';
38
42
  export * from './toolbar';