@e-infra/design-system 0.0.3 → 0.0.5

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