@idds/react 1.2.11 → 1.2.13

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.es.js CHANGED
@@ -6119,39 +6119,16 @@ const ConfirmationContext = createContext({
6119
6119
  confirm: () => Promise.resolve(false)
6120
6120
  });
6121
6121
  const useConfirmation = () => useContext(ConfirmationContext);
6122
- const defaultFooterActions = (cancelClassName, confirmClassName, cancelText, confirmText) => {
6122
+ const defaultFooterActions = (cancelClassName, confirmClassName, cancelText, confirmText, handleClose) => {
6123
6123
  return /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
6124
- /* @__PURE__ */ jsx(Button, { hierarchy: "custom", size: "sm", className: cancelClassName, children: cancelText }),
6125
- /* @__PURE__ */ jsx(Button, { hierarchy: "custom", size: "sm", className: confirmClassName, children: confirmText })
6126
- ] });
6127
- };
6128
- const ConfirmationProvider = ({
6129
- children
6130
- }) => {
6131
- const [options, setOptions] = useState({
6132
- title: "Confirmation",
6133
- message: "Are you sure you want to confirm?",
6134
- confirmText: "Yes",
6135
- cancelText: "No",
6136
- cancelClassName: "bg-background-primary border border-content-primary text-content-primary hover:bg-background-secondary",
6137
- confirmClassName: "bg-primary-primary text-white hover:bg-primary-primary/90",
6138
- footerActions: defaultFooterActions(
6139
- "bg-background-primary border border-content-primary text-content-primary hover:bg-background-secondary",
6140
- "bg-primary-primary text-white hover:bg-primary-primary/90",
6141
- "Yes",
6142
- "No"
6143
- )
6144
- });
6145
- const [pendingPromise, setPendingPromise] = useState(null);
6146
- /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
6147
6124
  /* @__PURE__ */ jsx(
6148
6125
  Button,
6149
6126
  {
6150
6127
  hierarchy: "custom",
6151
6128
  size: "sm",
6152
- className: options == null ? void 0 : options.cancelClassName,
6129
+ className: cancelClassName,
6153
6130
  onClick: () => handleClose(false),
6154
- children: options == null ? void 0 : options.cancelText
6131
+ children: cancelText
6155
6132
  }
6156
6133
  ),
6157
6134
  /* @__PURE__ */ jsx(
@@ -6159,36 +6136,47 @@ const ConfirmationProvider = ({
6159
6136
  {
6160
6137
  hierarchy: "custom",
6161
6138
  size: "sm",
6162
- className: (options == null ? void 0 : options.confirmClassName) ?? "bg-primary-primary text-white hover:bg-primary-primary/90",
6139
+ className: confirmClassName,
6163
6140
  onClick: () => handleClose(true),
6164
- children: options == null ? void 0 : options.confirmText
6141
+ children: confirmText
6165
6142
  }
6166
6143
  )
6167
6144
  ] });
6145
+ };
6146
+ const ConfirmationProvider = ({
6147
+ children
6148
+ }) => {
6149
+ const [options, setOptions] = useState(null);
6150
+ const [pendingPromise, setPendingPromise] = useState(null);
6151
+ const handleClose = (answer) => {
6152
+ if (pendingPromise) pendingPromise.resolve(answer);
6153
+ setOptions(null);
6154
+ setPendingPromise(null);
6155
+ };
6168
6156
  const confirm = (opts) => {
6169
6157
  return new Promise((resolve) => {
6158
+ const defaultCancelClassName = "bg-background-primary border border-content-primary text-content-primary hover:bg-background-secondary";
6159
+ const defaultConfirmClassName = "bg-primary-primary text-white hover:bg-primary-primary/90";
6160
+ const defaultCancelText = opts.cancelText ?? "Batal";
6161
+ const defaultConfirmText = opts.confirmText ?? "Ya";
6170
6162
  setOptions({
6171
6163
  title: opts.title ?? "Confirmation",
6172
6164
  message: opts.message,
6173
- confirmText: opts.confirmText ?? "Ya",
6174
- cancelText: opts.cancelText ?? "Batal",
6175
- cancelClassName: opts.cancelClassName ?? "bg-background-primary border border-content-primary text-content-primary hover:bg-background-secondary",
6176
- confirmClassName: opts.confirmClassName ?? "bg-primary-primary text-white hover:bg-primary-primary/90",
6177
- footerActions: opts.footerActions ?? defaultFooterActions(
6178
- opts.cancelClassName ?? "bg-background-primary border border-content-primary text-content-primary hover:bg-background-secondary",
6179
- opts.confirmClassName ?? "bg-primary-primary text-white hover:bg-primary-primary/90",
6180
- opts.cancelText ?? "Yes",
6181
- opts.confirmText ?? "No"
6182
- )
6165
+ confirmText: defaultConfirmText,
6166
+ cancelText: defaultCancelText,
6167
+ cancelClassName: opts.cancelClassName ?? defaultCancelClassName,
6168
+ confirmClassName: opts.confirmClassName ?? defaultConfirmClassName,
6169
+ footerActions: opts.footerActions ?? ((handleClose2) => defaultFooterActions(
6170
+ opts.cancelClassName ?? defaultCancelClassName,
6171
+ opts.confirmClassName ?? defaultConfirmClassName,
6172
+ defaultCancelText,
6173
+ defaultConfirmText,
6174
+ handleClose2
6175
+ ))
6183
6176
  });
6184
6177
  setPendingPromise({ resolve });
6185
6178
  });
6186
6179
  };
6187
- const handleClose = (answer) => {
6188
- if (pendingPromise) pendingPromise.resolve(answer);
6189
- setOptions(null);
6190
- setPendingPromise(null);
6191
- };
6192
6180
  return /* @__PURE__ */ jsxs(ConfirmationContext.Provider, { value: { confirm }, children: [
6193
6181
  children,
6194
6182
  options && /* @__PURE__ */ jsx(
@@ -6200,7 +6188,7 @@ const ConfirmationProvider = ({
6200
6188
  title: options.title,
6201
6189
  children: /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
6202
6190
  /* @__PURE__ */ jsx("div", { children: options.message }),
6203
- options == null ? void 0 : options.footerActions
6191
+ typeof options.footerActions === "function" ? options.footerActions(handleClose) : options.footerActions
6204
6192
  ] })
6205
6193
  }
6206
6194
  )