@cratis/components 1.6.8 → 1.7.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/cjs/CommandDialog/CommandStepper.css +24 -0
- package/dist/cjs/CommandDialog/CommandStepper.js +161 -0
- package/dist/cjs/CommandDialog/CommandStepper.js.map +1 -0
- package/dist/cjs/CommandDialog/StepperCommandDialog.js +5 -97
- package/dist/cjs/CommandDialog/StepperCommandDialog.js.map +1 -1
- package/dist/cjs/CommandDialog/index.js +3 -0
- package/dist/cjs/CommandDialog/index.js.map +1 -1
- package/dist/cjs/Common/Icon.js +22 -0
- package/dist/cjs/Common/Icon.js.map +1 -0
- package/dist/cjs/Common/index.js +2 -0
- package/dist/cjs/Common/index.js.map +1 -1
- package/dist/cjs/Toolbar/ToolbarButton.js +4 -3
- package/dist/cjs/Toolbar/ToolbarButton.js.map +1 -1
- package/dist/cjs/Toolbar/ToolbarFanOutItem.js +2 -1
- package/dist/cjs/Toolbar/ToolbarFanOutItem.js.map +1 -1
- package/dist/esm/CommandDialog/CommandStepper.css +24 -0
- package/dist/esm/CommandDialog/CommandStepper.d.ts +29 -0
- package/dist/esm/CommandDialog/CommandStepper.d.ts.map +1 -0
- package/dist/esm/CommandDialog/CommandStepper.js +158 -0
- package/dist/esm/CommandDialog/CommandStepper.js.map +1 -0
- package/dist/esm/CommandDialog/CommandStepper.stories.d.ts +9 -0
- package/dist/esm/CommandDialog/CommandStepper.stories.d.ts.map +1 -0
- package/dist/esm/CommandDialog/CommandStepper.stories.js +72 -0
- package/dist/esm/CommandDialog/CommandStepper.stories.js.map +1 -0
- package/dist/esm/CommandDialog/StepperCommandDialog.d.ts +1 -4
- package/dist/esm/CommandDialog/StepperCommandDialog.d.ts.map +1 -1
- package/dist/esm/CommandDialog/StepperCommandDialog.js +7 -99
- package/dist/esm/CommandDialog/StepperCommandDialog.js.map +1 -1
- package/dist/esm/CommandDialog/index.d.ts +1 -0
- package/dist/esm/CommandDialog/index.d.ts.map +1 -1
- package/dist/esm/CommandDialog/index.js +1 -0
- package/dist/esm/CommandDialog/index.js.map +1 -1
- package/dist/esm/Common/Icon.d.ts +8 -0
- package/dist/esm/Common/Icon.d.ts.map +1 -0
- package/dist/esm/Common/Icon.js +20 -0
- package/dist/esm/Common/Icon.js.map +1 -0
- package/dist/esm/Common/Icon.stories.d.ts +11 -0
- package/dist/esm/Common/Icon.stories.d.ts.map +1 -0
- package/dist/esm/Common/Icon.stories.js +26 -0
- package/dist/esm/Common/Icon.stories.js.map +1 -0
- package/dist/esm/Common/index.d.ts +1 -0
- package/dist/esm/Common/index.d.ts.map +1 -1
- package/dist/esm/Common/index.js +1 -0
- package/dist/esm/Common/index.js.map +1 -1
- package/dist/esm/Toolbar/Toolbar.stories.d.ts +1 -0
- package/dist/esm/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/esm/Toolbar/Toolbar.stories.js +10 -0
- package/dist/esm/Toolbar/Toolbar.stories.js.map +1 -1
- package/dist/esm/Toolbar/ToolbarButton.d.ts +2 -1
- package/dist/esm/Toolbar/ToolbarButton.d.ts.map +1 -1
- package/dist/esm/Toolbar/ToolbarButton.js +4 -3
- package/dist/esm/Toolbar/ToolbarButton.js.map +1 -1
- package/dist/esm/Toolbar/ToolbarFanOutItem.d.ts +2 -1
- package/dist/esm/Toolbar/ToolbarFanOutItem.d.ts.map +1 -1
- package/dist/esm/Toolbar/ToolbarFanOutItem.js +2 -1
- package/dist/esm/Toolbar/ToolbarFanOutItem.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/cjs/CommandDialog/StepperCommandDialog.css +0 -14
- package/dist/esm/CommandDialog/StepperCommandDialog.css +0 -14
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import React, { useMemo, useEffect, useState } from 'react';
|
|
3
|
+
import { Stepper } from 'primereact/stepper';
|
|
4
|
+
import { Button } from 'primereact/button';
|
|
5
|
+
import { CommandForm, useCommandFormContext, useCommandInstance, CommandFormFieldWrapper } from '@cratis/arc.react/commands';
|
|
6
|
+
import './CommandStepper.css';
|
|
7
|
+
|
|
8
|
+
/** Extracts the property name from an accessor function like `c => c.name`. */
|
|
9
|
+
const getPropertyName = (accessor) => {
|
|
10
|
+
if (typeof accessor !== 'function')
|
|
11
|
+
return '';
|
|
12
|
+
const fnStr = accessor.toString();
|
|
13
|
+
const match = fnStr.match(/\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
14
|
+
return match ? match[1] : '';
|
|
15
|
+
};
|
|
16
|
+
/** Recursively collects all CommandFormField property names from a React node tree. */
|
|
17
|
+
const extractFieldNamesFromNode = (nodes) => {
|
|
18
|
+
const names = [];
|
|
19
|
+
React.Children.forEach(nodes, (child) => {
|
|
20
|
+
if (!React.isValidElement(child))
|
|
21
|
+
return;
|
|
22
|
+
const component = child.type;
|
|
23
|
+
if (component.displayName === 'CommandFormField') {
|
|
24
|
+
const fieldProps = child.props;
|
|
25
|
+
const name = getPropertyName(fieldProps.value);
|
|
26
|
+
if (name)
|
|
27
|
+
names.push(name);
|
|
28
|
+
}
|
|
29
|
+
const childProps = child.props;
|
|
30
|
+
if (childProps.children != null) {
|
|
31
|
+
names.push(...extractFieldNamesFromNode(childProps.children));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return names;
|
|
35
|
+
};
|
|
36
|
+
const processChildren = (nodes) => {
|
|
37
|
+
return React.Children.map(nodes, (child) => {
|
|
38
|
+
if (!React.isValidElement(child))
|
|
39
|
+
return child;
|
|
40
|
+
const component = child.type;
|
|
41
|
+
if (component.displayName === 'CommandFormField') {
|
|
42
|
+
return jsx(CommandFormFieldWrapper, { field: child });
|
|
43
|
+
}
|
|
44
|
+
const childProps = child.props;
|
|
45
|
+
if (childProps.children != null) {
|
|
46
|
+
return React.cloneElement(child, {
|
|
47
|
+
children: processChildren(childProps.children)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return child;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const CommandStepperContent = ({ activeStep, visitedSteps, children, onActiveStepChange, onVisitedStepsChange, onStepErrorsChange, getFieldError, showNavigation = true, showSubmit = true, nextLabel = 'Next', previousLabel = 'Previous', okLabel = 'Submit', isBusy = false, isSubmitting = false, isSubmitDisabled = false, onSubmit, orientation = 'horizontal', headerPosition, linear = true, onChangeStep, start, end, pt, ptOptions, unstyled, }) => {
|
|
54
|
+
const stepCount = React.Children.count(children);
|
|
55
|
+
const isLastStep = activeStep >= stepCount - 1;
|
|
56
|
+
const isFirstStep = activeStep <= 0;
|
|
57
|
+
const stepFieldNames = useMemo(() => React.Children.toArray(children).map((step) => {
|
|
58
|
+
if (!React.isValidElement(step))
|
|
59
|
+
return [];
|
|
60
|
+
const stepProps = step.props;
|
|
61
|
+
return extractFieldNamesFromNode(stepProps.children);
|
|
62
|
+
}), [children]);
|
|
63
|
+
const stepErrors = useMemo(() => stepFieldNames.map(fields => fields.some(fieldName => !!getFieldError?.(fieldName))), [stepFieldNames, getFieldError]);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
onStepErrorsChange?.(stepErrors);
|
|
66
|
+
}, [onStepErrorsChange, stepErrors]);
|
|
67
|
+
const isCurrentStepInvalid = stepErrors[activeStep] ?? false;
|
|
68
|
+
const hasAnyStepErrors = stepErrors.some(hasError => hasError);
|
|
69
|
+
const stepperPt = useMemo(() => {
|
|
70
|
+
const userPt = pt;
|
|
71
|
+
const userStepperPanelPt = userPt?.stepperpanel;
|
|
72
|
+
const userNumberPt = userStepperPanelPt?.number;
|
|
73
|
+
return {
|
|
74
|
+
...userPt,
|
|
75
|
+
stepperpanel: {
|
|
76
|
+
...userStepperPanelPt,
|
|
77
|
+
number: (opts) => {
|
|
78
|
+
const existing = typeof userNumberPt === 'function'
|
|
79
|
+
? userNumberPt(opts)
|
|
80
|
+
: userNumberPt ?? {};
|
|
81
|
+
const idx = opts.context.index;
|
|
82
|
+
const hasError = stepErrors[idx] ?? false;
|
|
83
|
+
const isVisited = visitedSteps.has(idx);
|
|
84
|
+
const bgColor = hasError
|
|
85
|
+
? 'var(--red-500, #ef4444)'
|
|
86
|
+
: isVisited
|
|
87
|
+
? 'var(--green-500, #22c55e)'
|
|
88
|
+
: null;
|
|
89
|
+
if (!bgColor)
|
|
90
|
+
return existing;
|
|
91
|
+
const existingStyle = existing.style;
|
|
92
|
+
return {
|
|
93
|
+
...existing,
|
|
94
|
+
style: { ...existingStyle, backgroundColor: bgColor, color: '#fff' }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}, [pt, stepErrors, visitedSteps]);
|
|
100
|
+
const handleChangeStep = event => {
|
|
101
|
+
onChangeStep?.(event);
|
|
102
|
+
const index = event.index;
|
|
103
|
+
if (typeof index === 'number') {
|
|
104
|
+
if (index > activeStep) {
|
|
105
|
+
onVisitedStepsChange?.(new Set(visitedSteps).add(activeStep));
|
|
106
|
+
}
|
|
107
|
+
onActiveStepChange?.(index);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const handlePrevious = () => {
|
|
111
|
+
onActiveStepChange?.(Math.max(0, activeStep - 1));
|
|
112
|
+
};
|
|
113
|
+
const handleNext = () => {
|
|
114
|
+
onVisitedStepsChange?.(new Set(visitedSteps).add(activeStep));
|
|
115
|
+
onActiveStepChange?.(Math.min(stepCount - 1, activeStep + 1));
|
|
116
|
+
};
|
|
117
|
+
return (jsxs("div", { className: "cratis-command-stepper", children: [jsx(Stepper, { activeStep: activeStep, linear: linear, orientation: orientation, headerPosition: headerPosition, onChangeStep: handleChangeStep, start: start, end: end, pt: stepperPt, ptOptions: ptOptions, unstyled: unstyled, children: processChildren(children) }), showNavigation && (jsxs("div", { style: { display: 'flex', alignItems: 'center', width: '100%', gap: '0.75rem' }, children: [!isFirstStep && (jsx(Button, { label: previousLabel, icon: "pi pi-arrow-left", onClick: handlePrevious, disabled: isBusy, outlined: true, style: { width: 'auto' } })), jsx("div", { style: { flex: 1 } }), !isLastStep && (jsx(Button, { label: nextLabel, icon: "pi pi-arrow-right", iconPos: "right", onClick: handleNext, disabled: isBusy || isSubmitting || isCurrentStepInvalid, style: { width: 'auto' } })), isLastStep && showSubmit && (jsx(Button, { label: okLabel, icon: "pi pi-check", onClick: () => void onSubmit?.(), loading: isSubmitting, disabled: isBusy || isSubmitting || isSubmitDisabled || hasAnyStepErrors, autoFocus: true, style: { width: 'auto' } }))] }))] }));
|
|
118
|
+
};
|
|
119
|
+
const CommandStepperWrapper = ({ children, onStepErrorsChange, showNavigation, showSubmit, nextLabel, previousLabel, okLabel, isBusy, orientation, headerPosition, linear, onChangeStep, start, end, pt, ptOptions, unstyled, onSuccess, onValidationFailure, onFailed, onBeforeExecute, }) => {
|
|
120
|
+
const { getFieldError, isValid: isCommandFormValid, setCommandValues, setCommandResult } = useCommandFormContext();
|
|
121
|
+
const commandInstance = useCommandInstance();
|
|
122
|
+
const [activeStep, setActiveStep] = useState(0);
|
|
123
|
+
const [visitedSteps, setVisitedSteps] = useState(new Set([0]));
|
|
124
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
125
|
+
const handleSubmit = async () => {
|
|
126
|
+
if (onBeforeExecute) {
|
|
127
|
+
const transformedValues = onBeforeExecute(commandInstance);
|
|
128
|
+
setCommandValues(transformedValues);
|
|
129
|
+
}
|
|
130
|
+
setIsSubmitting(true);
|
|
131
|
+
let result;
|
|
132
|
+
try {
|
|
133
|
+
result = await commandInstance.execute();
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
setIsSubmitting(false);
|
|
137
|
+
}
|
|
138
|
+
if (!result.isSuccess) {
|
|
139
|
+
if (!result.isValid) {
|
|
140
|
+
await onValidationFailure?.(result.validationResults);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
await onFailed?.(result);
|
|
144
|
+
}
|
|
145
|
+
setCommandResult(result);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
await onSuccess?.(result.response);
|
|
149
|
+
};
|
|
150
|
+
return (jsx(CommandStepperContent, { activeStep: activeStep, visitedSteps: visitedSteps, onActiveStepChange: setActiveStep, onVisitedStepsChange: setVisitedSteps, onStepErrorsChange: onStepErrorsChange, getFieldError: getFieldError, showNavigation: showNavigation, showSubmit: showSubmit, nextLabel: nextLabel, previousLabel: previousLabel, okLabel: okLabel, isBusy: isBusy, isSubmitting: isSubmitting, isSubmitDisabled: !isCommandFormValid, onSubmit: handleSubmit, orientation: orientation, headerPosition: headerPosition, linear: linear, onChangeStep: onChangeStep, start: start, end: end, pt: pt, ptOptions: ptOptions, unstyled: unstyled, children: children }));
|
|
151
|
+
};
|
|
152
|
+
const CommandStepper = (props) => {
|
|
153
|
+
const { children, onStepErrorsChange, showNavigation, showSubmit, nextLabel, previousLabel, okLabel, isBusy, orientation, headerPosition, linear, onChangeStep, start, end, pt, ptOptions, unstyled, ...commandFormProps } = props;
|
|
154
|
+
return (jsx(CommandForm, { ...commandFormProps, children: jsx(CommandStepperWrapper, { onStepErrorsChange: onStepErrorsChange, showNavigation: showNavigation, showSubmit: showSubmit, nextLabel: nextLabel, previousLabel: previousLabel, okLabel: okLabel, isBusy: isBusy, orientation: orientation, headerPosition: headerPosition, linear: linear, onChangeStep: onChangeStep, start: start, end: end, pt: pt, ptOptions: ptOptions, unstyled: unstyled, onSuccess: props.onSuccess, onValidationFailure: props.onValidationFailure, onFailed: props.onFailed, onBeforeExecute: commandFormProps.onBeforeExecute, children: children }) }));
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export { CommandStepper, CommandStepperContent };
|
|
158
|
+
//# sourceMappingURL=CommandStepper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandStepper.js","sources":["../../../CommandDialog/CommandStepper.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs","PrimeStepper"],"mappings":";;;;;;;AAkEA;AACA,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QAAA,EAEjB,QAAQ,EAAA,CACW;AAEhC,CAAC;AAEM,MAAM,cAAc,GAAG,CAC1B,KAA+C,KAC/C;AACA,IAAA,MAAM,EACF,QAAQ,EACR,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,SAAS,EACT,aAAa,EACb,OAAO,EACP,MAAM,EACN,WAAW,EACX,cAAc,EACd,MAAM,EACN,YAAY,EACZ,KAAK,EACL,GAAG,EACH,EAAE,EACF,SAAS,EACT,QAAQ,EACR,GAAG,gBAAgB,EACtB,GAAG,KAAK;IAET,QACIA,IAAC,WAAW,EAAA,EAAA,GAA0B,gBAAgB,EAAA,QAAA,EAClDA,GAAA,CAAC,qBAAqB,EAAA,EAClB,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,EAAE,EACN,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,mBAAmB,EAAE,KAAK,CAAC,mBAAmB,EAC9C,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,eAAe,EAAE,gBAAgB,CAAC,eAAe,YAEhD,QAAQ,EAAA,CACW,EAAA,CACd;AAEtB;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { CommandStepper } from './CommandStepper';
|
|
3
|
+
import '@cratis/arc/validation';
|
|
4
|
+
declare const meta: Meta<typeof CommandStepper>;
|
|
5
|
+
export default meta;
|
|
6
|
+
type Story = StoryObj<typeof CommandStepper>;
|
|
7
|
+
export declare const Default: Story;
|
|
8
|
+
export declare const WithValidationIndicators: Story;
|
|
9
|
+
//# sourceMappingURL=CommandStepper.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandStepper.stories.d.ts","sourceRoot":"","sources":["../../../CommandDialog/CommandStepper.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,wBAAwB,CAAC;AAEhC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,cAAc,CAGrC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,cAAc,CAAC,CAAC;AAwD7C,eAAO,MAAM,OAAO,EAAE,KAgDrB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,KAoDtC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { StepperPanel } from 'primereact/stepperpanel';
|
|
4
|
+
import { CommandStepper } from './CommandStepper';
|
|
5
|
+
import { Command, CommandResult, CommandValidator } from '@cratis/arc/commands';
|
|
6
|
+
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
7
|
+
import { InputTextField, NumberField, TextAreaField } from '../CommandForm/fields';
|
|
8
|
+
import '@cratis/arc/validation';
|
|
9
|
+
const meta = {
|
|
10
|
+
title: 'CommandDialog/CommandStepper',
|
|
11
|
+
component: CommandStepper,
|
|
12
|
+
};
|
|
13
|
+
export default meta;
|
|
14
|
+
class CreateProjectValidator extends CommandValidator {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.ruleFor((c) => c.name).notEmpty().minLength(2).maxLength(100);
|
|
18
|
+
this.ruleFor((c) => c.email).notEmpty().emailAddress();
|
|
19
|
+
this.ruleFor((c) => c.description).notEmpty().minLength(10);
|
|
20
|
+
this.ruleFor((c) => c.budget).greaterThan(0);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class CreateProjectCommand extends Command {
|
|
24
|
+
route = '/api/projects/create';
|
|
25
|
+
validation = new CreateProjectValidator();
|
|
26
|
+
propertyDescriptors = [
|
|
27
|
+
new PropertyDescriptor('name', String),
|
|
28
|
+
new PropertyDescriptor('email', String),
|
|
29
|
+
new PropertyDescriptor('description', String),
|
|
30
|
+
new PropertyDescriptor('budget', Number),
|
|
31
|
+
];
|
|
32
|
+
name = '';
|
|
33
|
+
email = '';
|
|
34
|
+
description = '';
|
|
35
|
+
budget = 0;
|
|
36
|
+
constructor() {
|
|
37
|
+
super(Object, false);
|
|
38
|
+
}
|
|
39
|
+
get requestParameters() {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
get properties() {
|
|
43
|
+
return ['name', 'email', 'description', 'budget'];
|
|
44
|
+
}
|
|
45
|
+
async validate() {
|
|
46
|
+
const errors = this.validation?.validate(this) ?? [];
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
return CommandResult.validationFailed(errors);
|
|
49
|
+
}
|
|
50
|
+
return CommandResult.empty;
|
|
51
|
+
}
|
|
52
|
+
async execute() {
|
|
53
|
+
const validation = await this.validate();
|
|
54
|
+
if (!validation.isSuccess) {
|
|
55
|
+
return validation;
|
|
56
|
+
}
|
|
57
|
+
return CommandResult.empty;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export const Default = {
|
|
61
|
+
render: () => {
|
|
62
|
+
const [result, setResult] = useState('');
|
|
63
|
+
return (_jsxs("div", { style: { width: '600px', padding: '1.5rem' }, children: [_jsxs(CommandStepper, { command: CreateProjectCommand, autoServerValidate: false, validateOn: "change", onSuccess: async () => setResult('Command submitted successfully'), children: [_jsxs(StepperPanel, { header: "Basic Info", children: [_jsx(InputTextField, { value: c => c.name, title: "Project Name", placeholder: "Enter project name (min 2 chars)" }), _jsx(InputTextField, { value: c => c.email, title: "Contact Email", placeholder: "Enter contact email", type: "email" })] }), _jsxs(StepperPanel, { header: "Details", children: [_jsx(TextAreaField, { value: c => c.description, title: "Description", placeholder: "Describe the project (min 10 chars)", rows: 4 }), _jsx(NumberField, { value: c => c.budget, title: "Budget", placeholder: "Enter budget (must be > 0)" })] })] }), result && (_jsx("div", { className: "p-2 mt-3 border-round surface-100", style: { border: '1px solid var(--surface-border)' }, children: result }))] }));
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
export const WithValidationIndicators = {
|
|
67
|
+
render: () => {
|
|
68
|
+
const [result, setResult] = useState('');
|
|
69
|
+
return (_jsxs("div", { style: { width: '600px', padding: '1.5rem' }, children: [_jsxs(CommandStepper, { command: CreateProjectCommand, autoServerValidate: false, validateOn: "change", validateOnInit: true, nextLabel: "Continue", previousLabel: "Back", okLabel: "Create", onSuccess: async () => setResult('Project created successfully'), children: [_jsxs(StepperPanel, { header: "Basic Info", children: [_jsx(InputTextField, { value: c => c.name, title: "Project Name", placeholder: "Enter project name (min 2 chars)" }), _jsx(InputTextField, { value: c => c.email, title: "Contact Email", placeholder: "Enter contact email", type: "email" })] }), _jsxs(StepperPanel, { header: "Details", children: [_jsx(TextAreaField, { value: c => c.description, title: "Description", placeholder: "Describe the project (min 10 chars)", rows: 4 }), _jsx(NumberField, { value: c => c.budget, title: "Budget", placeholder: "Enter budget (must be > 0)" })] })] }), result && (_jsx("div", { className: "p-2 mt-3 border-round surface-100", style: { border: '1px solid var(--surface-border)' }, children: result }))] }));
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=CommandStepper.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandStepper.stories.js","sourceRoot":"","sources":["../../../CommandDialog/CommandStepper.stories.tsx"],"names":[],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|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { type DialogProps as PrimeDialogProps } from 'primereact/dialog';
|
|
2
|
-
import { type StepperProps } from 'primereact/stepper';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import { type CommandFormProps } from '@cratis/arc.react/commands';
|
|
5
4
|
import type { CloseDialog, ConfirmCallback, CancelCallback } from '../Dialogs/Dialog';
|
|
6
|
-
import './
|
|
7
|
-
type StepperCustomizationProps = Pick<StepperProps, 'orientation' | 'headerPosition' | 'linear' | 'onChangeStep' | 'start' | 'end' | 'pt' | 'ptOptions' | 'unstyled'>;
|
|
5
|
+
import { type StepperCustomizationProps } from './CommandStepper';
|
|
8
6
|
export interface StepperCommandDialogProps<TCommand extends object, TResponse = object> extends Omit<CommandFormProps<TCommand, TResponse>, 'children'>, StepperCustomizationProps {
|
|
9
7
|
title: string;
|
|
10
8
|
visible?: boolean;
|
|
@@ -22,5 +20,4 @@ export interface StepperCommandDialogProps<TCommand extends object, TResponse =
|
|
|
22
20
|
children?: React.ReactNode;
|
|
23
21
|
}
|
|
24
22
|
export declare const StepperCommandDialog: <TCommand extends object = object, TResponse = object>(props: StepperCommandDialogProps<TCommand, TResponse>) => import("react/jsx-runtime").JSX.Element;
|
|
25
|
-
export {};
|
|
26
23
|
//# sourceMappingURL=StepperCommandDialog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepperCommandDialog.d.ts","sourceRoot":"","sources":["../../../CommandDialog/StepperCommandDialog.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAyB,KAAK,WAAW,IAAI,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"StepperCommandDialog.d.ts","sourceRoot":"","sources":["../../../CommandDialog/StepperCommandDialog.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAyB,KAAK,WAAW,IAAI,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhG,OAAO,KAAmB,MAAM,OAAO,C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/dialog';
|
|
4
|
-
import { Stepper } from 'primereact/stepper';
|
|
5
4
|
import { Button } from 'primereact/button';
|
|
6
|
-
import React, { useState
|
|
7
|
-
import { CommandForm, useCommandFormContext, useCommandInstance
|
|
8
|
-
import './
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
|
+
import { CommandForm, useCommandFormContext, useCommandInstance } from '@cratis/arc.react/commands';
|
|
7
|
+
import { CommandStepperContent } from './CommandStepper.js';
|
|
9
8
|
|
|
10
|
-
/** Extracts the property name from an accessor function like `c => c.name`. */
|
|
11
|
-
const getPropertyName = (accessor) => {
|
|
12
|
-
if (typeof accessor !== 'function')
|
|
13
|
-
return '';
|
|
14
|
-
const fnStr = accessor.toString();
|
|
15
|
-
const match = fnStr.match(/\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
16
|
-
return match ? match[1] : '';
|
|
17
|
-
};
|
|
18
|
-
/** Recursively collects all CommandFormField property names from a React node tree. */
|
|
19
|
-
const extractFieldNamesFromNode = (nodes) => {
|
|
20
|
-
const names = [];
|
|
21
|
-
React.Children.forEach(nodes, (child) => {
|
|
22
|
-
if (!React.isValidElement(child))
|
|
23
|
-
return;
|
|
24
|
-
const component = child.type;
|
|
25
|
-
if (component.displayName === 'CommandFormField') {
|
|
26
|
-
const fieldProps = child.props;
|
|
27
|
-
const name = getPropertyName(fieldProps.value);
|
|
28
|
-
if (name)
|
|
29
|
-
names.push(name);
|
|
30
|
-
}
|
|
31
|
-
const childProps = child.props;
|
|
32
|
-
if (childProps.children != null) {
|
|
33
|
-
names.push(...extractFieldNamesFromNode(childProps.children));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return names;
|
|
37
|
-
};
|
|
38
9
|
const StepperCommandDialogWrapper = ({ title, visible = true, width = '600px', style, contentStyle, resizable = false, isValid, onClose, onConfirm, onCancel, onSuccess, onValidationFailure, onFailed, onBeforeExecute, okLabel = 'Submit', nextLabel = 'Next', previousLabel = 'Previous', orientation = 'horizontal', headerPosition, linear = true, onChangeStep, start, end, pt, ptOptions, unstyled, children }) => {
|
|
39
10
|
const { setCommandValues, setCommandResult, isValid: isCommandFormValid, getFieldError } = useCommandFormContext();
|
|
40
11
|
const commandInstance = useCommandInstance();
|
|
41
12
|
const [isBusy, setIsBusy] = useState(false);
|
|
42
13
|
const [activeStep, setActiveStep] = useState(0);
|
|
43
14
|
const [visitedSteps, setVisitedSteps] = useState(new Set([0]));
|
|
15
|
+
const [stepErrors, setStepErrors] = useState([]);
|
|
44
16
|
let contextCloseDialog;
|
|
45
17
|
try {
|
|
46
18
|
const context = useDialogContext();
|
|
@@ -53,15 +25,7 @@ const StepperCommandDialogWrapper = ({ title, visible = true, width = '600px', s
|
|
|
53
25
|
const isLastStep = activeStep === stepCount - 1;
|
|
54
26
|
const isFirstStep = activeStep === 0;
|
|
55
27
|
const isDialogValid = isValid !== false && isCommandFormValid;
|
|
56
|
-
|
|
57
|
-
// Used to determine whether a step has validation errors for the indicator badge.
|
|
58
|
-
const stepFieldNames = useMemo(() => React.Children.toArray(children).map((step) => {
|
|
59
|
-
if (!React.isValidElement(step))
|
|
60
|
-
return [];
|
|
61
|
-
const stepProps = step.props;
|
|
62
|
-
return extractFieldNamesFromNode(stepProps.children);
|
|
63
|
-
}), [children]);
|
|
64
|
-
const stepHasError = (stepIndex) => stepFieldNames[stepIndex]?.some(fieldName => !!(getFieldError?.(fieldName))) ?? false;
|
|
28
|
+
const isCurrentStepInvalid = stepErrors[activeStep] ?? false;
|
|
65
29
|
const handleClose = async (result) => {
|
|
66
30
|
let shouldCloseThroughContext = true;
|
|
67
31
|
if (result === DialogResult.Ok || result === DialogResult.Yes) {
|
|
@@ -114,68 +78,12 @@ const StepperCommandDialogWrapper = ({ title, visible = true, width = '600px', s
|
|
|
114
78
|
await onSuccess?.(result.response);
|
|
115
79
|
await handleClose(DialogResult.Ok);
|
|
116
80
|
};
|
|
117
|
-
const processChildren = (nodes) => {
|
|
118
|
-
return React.Children.map(nodes, (child) => {
|
|
119
|
-
if (!React.isValidElement(child))
|
|
120
|
-
return child;
|
|
121
|
-
const component = child.type;
|
|
122
|
-
if (component.displayName === 'CommandFormField') {
|
|
123
|
-
return jsx(CommandFormFieldWrapper, { field: child });
|
|
124
|
-
}
|
|
125
|
-
const childProps = child.props;
|
|
126
|
-
if (childProps.children != null) {
|
|
127
|
-
return React.cloneElement(child, {
|
|
128
|
-
children: processChildren(childProps.children)
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return child;
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Builds the passthrough `pt` object for PrimeStepper, injecting an inline
|
|
136
|
-
* style onto the step *number* span to colour it red (errors) or green (visited
|
|
137
|
-
* and valid). Targeting the number span — rather than the header `<li>` — means
|
|
138
|
-
* PrimeReact's default `p-stepper-header` class and all its layout/separator
|
|
139
|
-
* CSS are never disturbed.
|
|
140
|
-
* Merges with any user-supplied `pt` prop.
|
|
141
|
-
*/
|
|
142
|
-
const stepperPt = useMemo(() => {
|
|
143
|
-
const userPt = pt;
|
|
144
|
-
const userStepperPanelPt = userPt?.stepperpanel;
|
|
145
|
-
const userNumberPt = userStepperPanelPt?.number;
|
|
146
|
-
return {
|
|
147
|
-
...userPt,
|
|
148
|
-
stepperpanel: {
|
|
149
|
-
...userStepperPanelPt,
|
|
150
|
-
number: (opts) => {
|
|
151
|
-
const existing = typeof userNumberPt === 'function'
|
|
152
|
-
? userNumberPt(opts)
|
|
153
|
-
: userNumberPt ?? {};
|
|
154
|
-
const idx = opts.context.index;
|
|
155
|
-
const hasError = stepFieldNames[idx]?.some(fieldName => !!(getFieldError?.(fieldName))) ?? false;
|
|
156
|
-
const isVisited = visitedSteps.has(idx);
|
|
157
|
-
const bgColor = hasError
|
|
158
|
-
? 'var(--red-500, #ef4444)'
|
|
159
|
-
: isVisited
|
|
160
|
-
? 'var(--green-500, #22c55e)'
|
|
161
|
-
: null;
|
|
162
|
-
if (!bgColor)
|
|
163
|
-
return existing;
|
|
164
|
-
const existingStyle = existing.style;
|
|
165
|
-
return {
|
|
166
|
-
...existing,
|
|
167
|
-
style: { ...existingStyle, backgroundColor: bgColor, color: '#fff' }
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}, [pt, stepFieldNames, getFieldError, visitedSteps]);
|
|
173
81
|
const headerElement = (jsx("div", { className: "inline-flex align-items-center justify-content-center gap-2", children: jsx("span", { className: "font-bold white-space-nowrap", children: title }) }));
|
|
174
82
|
const footer = (jsxs("div", { className: "flex align-items-center w-full gap-3", children: [!isFirstStep && (jsx(Button, { label: previousLabel, icon: "pi pi-arrow-left", onClick: () => setActiveStep(s => s - 1), disabled: isBusy, outlined: true })), jsx("div", { className: "flex-1" }), !isLastStep && (jsx(Button, { label: nextLabel, icon: "pi pi-arrow-right", iconPos: "right", onClick: () => {
|
|
175
83
|
setVisitedSteps(prev => new Set(prev).add(activeStep));
|
|
176
84
|
setActiveStep(s => s + 1);
|
|
177
|
-
}, disabled: isBusy ||
|
|
178
|
-
return (jsx(Dialog, { header: headerElement, modal: true, footer: footer, onHide: () => handleClose(DialogResult.Cancelled), visible: visible, style: { width, ...style }, contentStyle: contentStyle, resizable: resizable, closable: true, children: jsx(
|
|
85
|
+
}, disabled: isBusy || isCurrentStepInvalid })), isLastStep && isDialogValid && (jsx(Button, { label: okLabel, icon: "pi pi-check", onClick: handleSubmit, loading: isBusy, disabled: isBusy, autoFocus: true }))] }));
|
|
86
|
+
return (jsx(Dialog, { header: headerElement, modal: true, footer: footer, onHide: () => handleClose(DialogResult.Cancelled), visible: visible, style: { width, ...style }, contentStyle: contentStyle, resizable: resizable, closable: true, children: jsx(CommandStepperContent, { activeStep: activeStep, visitedSteps: visitedSteps, getFieldError: getFieldError, onActiveStepChange: setActiveStep, onVisitedStepsChange: setVisitedSteps, onStepErrorsChange: setStepErrors, showNavigation: false, showSubmit: false, linear: linear, orientation: orientation, headerPosition: headerPosition, onChangeStep: onChangeStep, start: start, end: end, pt: pt, ptOptions: ptOptions, unstyled: unstyled, children: children }) }));
|
|
179
87
|
};
|
|
180
88
|
const StepperCommandDialogComponent = (props) => {
|
|
181
89
|
const { title, visible, width, style, contentStyle, resizable, isValid, onClose, onConfirm, onCancel, okLabel, nextLabel, previousLabel, orientation, headerPosition, linear, onChangeStep, start, end, pt, ptOptions, unstyled, children, ...commandFormProps } = props;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepperCommandDialog.js","sources":["../../../CommandDialog/StepperCommandDialog.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs","PrimeDialog"
|
|
1
|
+
{"version":3,"file":"StepperCommandDialog.js","sources":["../../../CommandDialog/StepperCommandDialog.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs","PrimeDialog"],"mappings":";;;;;;;;AAkDA,MAAM,2BAA2B,GAAG,CAA8C,EAC9E,KAAK,EACL,OAAO,GAAG,IAAI,EACd,KAAK,GAAG,OAAO,EACf,KAAK,EACL,YAAY,EACZ,SAAS,GAAG,KAAK,EACjB,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,EACR,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,OAAO,GAAG,QAAQ,EAClB,SAAS,GAAG,MAAM,EAClB,aAAa,GAAG,UAAU,EAC1B,WAAW,GAAG,YAAY,EAC1B,cAAc,EACd,MAAM,GAAG,IAAI,EACb,YAAY,EACZ,KAAK,EACL,GAAG,EACH,EAAE,EACF,SAAS,EACT,QAAQ,EACR,QAAQ,EAoBiB,KAAI;AAC7B,IAAA,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,GAAG,qBAAqB,EAAY;AAC5H,IAAA,MAAM,eAAe,GAAG,kBAAkB,EAAY;IACtD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC3C,MAAM,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,EAChB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,mBAAmB,EAAE,KAAK,CAAC,mBAAmB,EAC9C,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,eAAe,EAAE,gBAAgB,CAAC,eAAe,EACjD,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,EAAE,EACN,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAAA,QAAA,EAEjB,QAAQ,EAAA,CACiB,EAAA,CACpB;AAEtB,CAAC;AAEM,MAAM,oBAAoB,GAAG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../CommandDialog/index.ts"],"names":[],"mappings":"AAGA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../CommandDialog/index.ts"],"names":[],"mappings":"AAGA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../CommandDialog/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../CommandDialog/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;AACA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export type Icon = string | ReactNode;
|
|
3
|
+
export interface IconDisplayProps {
|
|
4
|
+
icon: Icon;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const IconDisplay: ({ icon, className }: IconDisplayProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=Icon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.d.ts","sourceRoot":"","sources":["../../../Common/Icon.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMlC,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,SAAS,CAAC;AAGtC,MAAM,WAAW,gBAAgB;IAE7B,IAAI,EAAE,IAAI,CAAC;IAGX,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAUD,eAAO,MAAM,WAAW,GAAI,qBAAqB,gBAAgB,4CAMhE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Renders an {@link Icon} value.
|
|
5
|
+
*
|
|
6
|
+
* - When `icon` is a non-empty string it is treated as a PrimeIcons (or other icon-font)
|
|
7
|
+
* CSS class and rendered as `<i className={icon} />`.
|
|
8
|
+
* - Otherwise the value is rendered as-is, allowing any React node (SVG, component, etc.)
|
|
9
|
+
* to be used as an icon.
|
|
10
|
+
*/
|
|
11
|
+
const IconDisplay = ({ icon, className }) => {
|
|
12
|
+
if (typeof icon === 'string' && icon.length > 0) {
|
|
13
|
+
const combined = className ? `${icon} ${className}` : icon;
|
|
14
|
+
return jsx("i", { className: combined });
|
|
15
|
+
}
|
|
16
|
+
return jsx(Fragment, { children: icon });
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { IconDisplay };
|
|
20
|
+
//# sourceMappingURL=Icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.js","sources":["../../../Common/Icon.tsx"],"sourcesContent":[null],"names":["_jsx","_Fragment"],"mappings":";;AAoBA;;;;;;;AAOG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAoB,KAAI;IACjE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;AAC7C,QAAA,MAAM,QAAQ,GAAG,SAAS,GAAG,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,SAAS,CAAA,CAAE,GAAG,IAAI;AAC1D,QAAA,OAAOA,GAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAE,QAAQ,GAAI;IACrC;IACA,OAAOA,GAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAG,IAAI,EAAA,CAAI;AACtB;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { IconDisplay } from './Icon';
|
|
3
|
+
declare const meta: Meta<typeof IconDisplay>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof IconDisplay>;
|
|
6
|
+
export declare const StringIcon: Story;
|
|
7
|
+
export declare const StringIconWithExtraClass: Story;
|
|
8
|
+
export declare const SvgReactNode: Story;
|
|
9
|
+
export declare const ArbitraryReactNode: Story;
|
|
10
|
+
export declare const StringVsReactNode: Story;
|
|
11
|
+
//# sourceMappingURL=Icon.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.stories.d.ts","sourceRoot":"","sources":["../../../Common/Icon.stories.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,WAAW,CAMlC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,WAAW,CAAC,CAAC;AAG1C,eAAO,MAAM,UAAU,EAAE,KAExB,CAAC;AAGF,eAAO,MAAM,wBAAwB,EAAE,KAEtC,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,KAiB1B,CAAC;AAGF,eAAO,MAAM,kBAAkB,EAAE,KAIhC,CAAC;AAMF,eAAO,MAAM,iBAAiB,EAAE,KA8B/B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { IconDisplay } from './Icon';
|
|
3
|
+
const meta = {
|
|
4
|
+
title: 'Common/IconDisplay',
|
|
5
|
+
component: IconDisplay,
|
|
6
|
+
parameters: {
|
|
7
|
+
layout: 'centered',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
export const StringIcon = {
|
|
12
|
+
render: () => _jsx(IconDisplay, { icon: 'pi pi-home' }),
|
|
13
|
+
};
|
|
14
|
+
export const StringIconWithExtraClass = {
|
|
15
|
+
render: () => _jsx(IconDisplay, { icon: 'pi pi-home', className: 'text-3xl' }),
|
|
16
|
+
};
|
|
17
|
+
export const SvgReactNode = {
|
|
18
|
+
render: () => (_jsx(IconDisplay, { icon: _jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: '24', height: '24', fill: 'currentColor', "aria-hidden": 'true', children: _jsx("path", { d: 'M12 2a10 10 0 1 0 0 20A10 10 0 0 0 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z' }) }) })),
|
|
19
|
+
};
|
|
20
|
+
export const ArbitraryReactNode = {
|
|
21
|
+
render: () => (_jsx(IconDisplay, { icon: _jsx("span", { style: { fontSize: '1.5rem' }, children: "\uD83D\uDE80" }) })),
|
|
22
|
+
};
|
|
23
|
+
export const StringVsReactNode = {
|
|
24
|
+
render: () => (_jsxs("div", { style: { display: 'flex', gap: '2rem', alignItems: 'center' }, children: [_jsxs("div", { style: { textAlign: 'center' }, children: [_jsx(IconDisplay, { icon: 'pi pi-home', className: 'text-2xl' }), _jsx("p", { style: { fontSize: '0.75rem', marginTop: '0.5rem', color: 'var(--text-color-secondary)' }, children: "string (CSS class)" })] }), _jsxs("div", { style: { textAlign: 'center' }, children: [_jsx(IconDisplay, { icon: _jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: '24', height: '24', fill: 'currentColor', "aria-hidden": 'true', children: _jsx("path", { d: 'M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z' }) }) }), _jsx("p", { style: { fontSize: '0.75rem', marginTop: '0.5rem', color: 'var(--text-color-secondary)' }, children: "ReactNode (SVG)" })] })] })),
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=Icon.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.stories.js","sourceRoot":"","sources":["../../../Common/Icon.stories.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,IAAI,GAA6B;IACnC,KAAK,EAAE,oBAAoB;IAC3B,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE;QACR,MAAM,EAAE,UAAU;KACrB;CACJ,CAAC;AAEF,eAAe,IAAI,CAAC;AAIpB,MAAM,CAAC,MAAM,UAAU,GAAU;IAC7B,MAAM,EAAE,GAAG,EAAE,CAAC,KAAC,WAAW,IAAC,IAAI,EAAC,YAAY,GAAG;CAClD,CAAC;AAGF,MAAM,CAAC,MAAM,wBAAwB,GAAU;IAC3C,MAAM,EAAE,GAAG,EAAE,CAAC,KAAC,WAAW,IAAC,IAAI,EAAC,YAAY,EAAC,SAAS,EAAC,UAAU,GAAG;CACvE,CAAC;AAGF,MAAM,CAAC,MAAM,YAAY,GAAU;IAC/B,MAAM,EAAE,GAAG,EAAE,CAAC,CACV,KAAC,WAAW,IACR,IAAI,EACA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}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../Common/index.ts"],"names":[],"mappings":"AAGA,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../Common/index.ts"],"names":[],"mappings":"AAGA,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
|