@e-infra/design-system 0.0.3 → 0.0.4

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/index.cjs.js CHANGED
@@ -4006,6 +4006,177 @@ const Toaster = ({ ...props }) => {
4006
4006
  }
4007
4007
  );
4008
4008
  };
4009
+ const StepperContext = React__namespace.createContext(
4010
+ void 0
4011
+ );
4012
+ function useStepper() {
4013
+ const context = React__namespace.useContext(StepperContext);
4014
+ if (!context) {
4015
+ throw new Error("useStepper must be used within a Stepper");
4016
+ }
4017
+ return context;
4018
+ }
4019
+ function Stepper({
4020
+ children,
4021
+ initialStep = 0,
4022
+ totalSteps: totalStepsProp,
4023
+ onStepChange
4024
+ }) {
4025
+ const [currentStep, setCurrentStep] = React__namespace.useState(initialStep);
4026
+ const steps = React__namespace.Children.toArray(children);
4027
+ const totalSteps = totalStepsProp ?? steps.length;
4028
+ const nextStep = React__namespace.useCallback(() => {
4029
+ setCurrentStep((prev) => {
4030
+ const next = Math.min(prev + 1, totalSteps - 1);
4031
+ onStepChange?.(next);
4032
+ return next;
4033
+ });
4034
+ }, [totalSteps, onStepChange]);
4035
+ const previousStep = React__namespace.useCallback(() => {
4036
+ setCurrentStep((prev) => {
4037
+ const next = Math.max(prev - 1, 0);
4038
+ onStepChange?.(next);
4039
+ return next;
4040
+ });
4041
+ }, [onStepChange]);
4042
+ const goToStep = React__namespace.useCallback(
4043
+ (step) => {
4044
+ const validStep = Math.max(0, Math.min(step, totalSteps - 1));
4045
+ setCurrentStep(validStep);
4046
+ onStepChange?.(validStep);
4047
+ },
4048
+ [totalSteps, onStepChange]
4049
+ );
4050
+ React__namespace.useEffect(() => {
4051
+ if (initialStep !== currentStep) {
4052
+ setCurrentStep(initialStep);
4053
+ }
4054
+ }, [initialStep]);
4055
+ return /* @__PURE__ */ jsxRuntime.jsx(
4056
+ StepperContext.Provider,
4057
+ {
4058
+ value: {
4059
+ currentStep,
4060
+ totalSteps,
4061
+ nextStep,
4062
+ previousStep,
4063
+ goToStep
4064
+ },
4065
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full", children })
4066
+ }
4067
+ );
4068
+ }
4069
+ function StepperHeader({ steps, className }) {
4070
+ const { currentStep, previousStep, nextStep, totalSteps } = useStepper();
4071
+ const progressPercentage = (currentStep + 1) / totalSteps * 100;
4072
+ return /* @__PURE__ */ jsxRuntime.jsx("nav", { "aria-label": "Progress", className: cn("mb-8", className), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4 items-center", children: [
4073
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-10 w-full justify-center", children: [
4074
+ /* @__PURE__ */ jsxRuntime.jsxs(
4075
+ Button,
4076
+ {
4077
+ variant: "secondary",
4078
+ size: "sm",
4079
+ onClick: previousStep,
4080
+ disabled: currentStep === 0,
4081
+ className: "gap-1.5",
4082
+ children: [
4083
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "h-3.5 w-3.5" }),
4084
+ "Previous"
4085
+ ]
4086
+ }
4087
+ ),
4088
+ /* @__PURE__ */ jsxRuntime.jsx(Progress, { value: progressPercentage, className: "w-105" }),
4089
+ /* @__PURE__ */ jsxRuntime.jsxs(
4090
+ Button,
4091
+ {
4092
+ variant: "secondary",
4093
+ size: "sm",
4094
+ onClick: nextStep,
4095
+ disabled: currentStep === totalSteps - 1,
4096
+ className: "gap-1.5",
4097
+ children: [
4098
+ "Next",
4099
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-3.5 w-3.5" })
4100
+ ]
4101
+ }
4102
+ )
4103
+ ] }),
4104
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex items-center justify-center gap-5", children: [
4105
+ steps.map((_, index) => {
4106
+ if (index === 0) return null;
4107
+ const isComplete = index <= currentStep;
4108
+ return /* @__PURE__ */ jsxRuntime.jsx(
4109
+ "div",
4110
+ {
4111
+ className: cn(
4112
+ "absolute h-px w-[133px]",
4113
+ "top-2",
4114
+ isComplete ? "bg-slate-700" : "bg-border"
4115
+ ),
4116
+ style: {
4117
+ left: `calc(${(index - 1) * 25}% + ${56 + (index - 1) * 20}px)`
4118
+ }
4119
+ },
4120
+ `connector-${index}`
4121
+ );
4122
+ }),
4123
+ steps.map((step, index) => {
4124
+ const isComplete = index < currentStep;
4125
+ const isCurrent = index === currentStep;
4126
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4127
+ "div",
4128
+ {
4129
+ className: "flex flex-col items-center gap-1 w-28 relative z-10",
4130
+ children: [
4131
+ /* @__PURE__ */ jsxRuntime.jsx(
4132
+ "button",
4133
+ {
4134
+ onClick: () => {
4135
+ },
4136
+ className: cn(
4137
+ "flex items-center justify-center w-4 h-4 rounded-full text-white text-[11px] font-semibold transition-colors",
4138
+ isComplete && "bg-[#36a769]",
4139
+ isCurrent && "bg-[#c9a224]",
4140
+ !isComplete && !isCurrent && "bg-[#999]"
4141
+ ),
4142
+ children: index + 1
4143
+ }
4144
+ ),
4145
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-foreground text-center leading-tight", children: step.label })
4146
+ ]
4147
+ },
4148
+ step.label
4149
+ );
4150
+ })
4151
+ ] })
4152
+ ] }) });
4153
+ }
4154
+ function StepperContent({ children, className }) {
4155
+ const { currentStep } = useStepper();
4156
+ const steps = React__namespace.Children.toArray(children);
4157
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("py-4", className), children: steps[currentStep] || null });
4158
+ }
4159
+ function StepperFooter({
4160
+ children,
4161
+ className,
4162
+ showDefaultButtons = true,
4163
+ nextLabel = "Next",
4164
+ previousLabel = "Previous",
4165
+ finishLabel = "Finish",
4166
+ onFinish
4167
+ }) {
4168
+ const { currentStep, totalSteps, nextStep, previousStep } = useStepper();
4169
+ const isFirstStep = currentStep === 0;
4170
+ const isLastStep = currentStep === totalSteps - 1;
4171
+ if (children) {
4172
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("mt-8 flex justify-between", className), children });
4173
+ }
4174
+ if (!showDefaultButtons) return null;
4175
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("mt-8 flex justify-between", className), children: [
4176
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", onClick: previousStep, disabled: isFirstStep, children: previousLabel }),
4177
+ isLastStep ? /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: onFinish, children: finishLabel }) : /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: nextStep, children: nextLabel })
4178
+ ] });
4179
+ }
4009
4180
  function Switch({
4010
4181
  className,
4011
4182
  ...props
@@ -4515,6 +4686,10 @@ exports.SidebarSeparator = SidebarSeparator;
4515
4686
  exports.SidebarTrigger = SidebarTrigger;
4516
4687
  exports.Skeleton = Skeleton;
4517
4688
  exports.Slider = Slider;
4689
+ exports.Stepper = Stepper;
4690
+ exports.StepperContent = StepperContent;
4691
+ exports.StepperFooter = StepperFooter;
4692
+ exports.StepperHeader = StepperHeader;
4518
4693
  exports.Switch = Switch;
4519
4694
  exports.Table = Table;
4520
4695
  exports.TableBody = TableBody;
@@ -4545,4 +4720,5 @@ exports.toggleVariants = toggleVariants;
4545
4720
  exports.useFormField = useFormField;
4546
4721
  exports.useIsMobile = useIsMobile;
4547
4722
  exports.useSidebar = useSidebar;
4723
+ exports.useStepper = useStepper;
4548
4724
  //# sourceMappingURL=index.cjs.js.map