@julien-wiegandt/open-ui 0.1.66 → 0.1.68

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.
@@ -1,7 +1,10 @@
1
1
  import { Theme } from '../theme/types';
2
2
  export type IThemeContext = {
3
3
  theme: Theme;
4
- setTheme: (index: number) => void;
4
+ setTheme: ({ index, theme }: {
5
+ index?: number;
6
+ theme?: Theme;
7
+ }) => void;
5
8
  };
6
9
  export declare const ThemeContext: import('react').Context<IThemeContext>;
7
10
  export declare const ThemeContextProvider: (params: {
package/dist/open-ui.js CHANGED
@@ -3627,18 +3627,30 @@ const St = {
3627
3627
  primary: {
3628
3628
  dark: "#162a55",
3629
3629
  main: "#166FEE",
3630
- light: "#daeeff"
3630
+ light: "#daeeff",
3631
+ darker: "#162a55",
3632
+ lighter: "#daeeff"
3631
3633
  },
3632
3634
  secondary: {
3633
3635
  dark: "#7c420b",
3634
3636
  main: "#ffbf00",
3635
- light: "#fffbc5"
3637
+ light: "#fffbc5",
3638
+ darker: "#7c420b",
3639
+ lighter: "#fffbc5"
3640
+ },
3641
+ default: {
3642
+ dark: "#000000",
3643
+ main: "#1e1e1e",
3644
+ light: "#d1d1d1",
3645
+ darker: "#000000",
3646
+ lighter: "#d1d1d1"
3636
3647
  },
3637
- default: { dark: "#000000", main: "#1e1e1e", light: "#d1d1d1" },
3638
3648
  error: {
3639
3649
  dark: "#43110c",
3640
3650
  main: "#e74c3c",
3641
- light: "#fcd0cc"
3651
+ light: "#fcd0cc",
3652
+ darker: "#43110c",
3653
+ lighter: "#fcd0cc"
3642
3654
  }
3643
3655
  }
3644
3656
  }, Oh = () => /* @__PURE__ */ O.jsxs(
@@ -4407,11 +4419,28 @@ const Cd = (n, e) => e === "sm" ? `${Number(n) / (8 / 7)}px` : `${n}px`, _c = (n
4407
4419
  );
4408
4420
  kt.displayName = "Text";
4409
4421
  const yc = (n) => {
4410
- if (n === "transparent") return "#000000";
4411
- let e = n.startsWith("#") ? n.slice(1) : n;
4412
- if (e.length === 3 && (e = e.split("").map((s) => s + s).join("")), e.length !== 6)
4413
- throw new Error("Invalid hexadecimal color format.");
4414
- const t = parseInt(e.substring(0, 2), 16), r = parseInt(e.substring(2, 4), 16), i = parseInt(e.substring(4, 6), 16);
4422
+ const e = n.trim().toLowerCase();
4423
+ if (e === "transparent") return "#000000";
4424
+ let t = 0, r = 0, i = 0;
4425
+ if (e.startsWith("#")) {
4426
+ let s = e.slice(1);
4427
+ if (s.length === 3 || s.length === 4 ? s = s.slice(0, 3).split("").map((a) => a + a).join("") : s.length === 8 && (s = s.slice(0, 6)), s.length !== 6) throw new Error("Invalid hexadecimal color format.");
4428
+ t = parseInt(s.substring(0, 2), 16), r = parseInt(s.substring(2, 4), 16), i = parseInt(s.substring(4, 6), 16);
4429
+ } else if (e.startsWith("rgb")) {
4430
+ const s = e.match(/-?\d+(\.\d+)?/g)?.map(Number);
4431
+ if (!s || s.length < 3) throw new Error("Invalid RGB color format.");
4432
+ [t, r, i] = s;
4433
+ } else if (e.startsWith("hsl")) {
4434
+ const s = e.match(/-?\d+(\.\d+)?/g)?.map(Number);
4435
+ if (!s || s.length < 3) throw new Error("Invalid HSL color format.");
4436
+ let [a, c, u] = s;
4437
+ c /= 100, u /= 100;
4438
+ const f = (1 - Math.abs(2 * u - 1)) * c, d = f * (1 - Math.abs(a / 60 % 2 - 1)), p = u - f / 2;
4439
+ let l = 0, g = 0, h = 0;
4440
+ 0 <= a && a < 60 ? (l = f, g = d, h = 0) : 60 <= a && a < 120 ? (l = d, g = f, h = 0) : 120 <= a && a < 180 ? (l = 0, g = f, h = d) : 180 <= a && a < 240 ? (l = 0, g = d, h = f) : 240 <= a && a < 300 ? (l = d, g = 0, h = f) : 300 <= a && a < 360 && (l = f, g = 0, h = d), t = Math.round((l + p) * 255), r = Math.round((g + p) * 255), i = Math.round((h + p) * 255);
4441
+ } else
4442
+ throw new Error("Unsupported color format.");
4443
+ if (isNaN(t) || isNaN(r) || isNaN(i)) throw new Error("Invalid color values.");
4415
4444
  return (t * 299 + r * 587 + i * 114) / 1e3 >= 128 ? "#000000" : "#FFFFFF";
4416
4445
  }, Yt = ({
4417
4446
  color: n,
@@ -4770,6 +4799,7 @@ const $d = mt.input`
4770
4799
  &::-webkit-color-swatch-wrapper {
4771
4800
  padding: 0;
4772
4801
  border-radius: ${({ theme: n }) => St[n.radius]};
4802
+ cursor: pointer;
4773
4803
  }
4774
4804
 
4775
4805
  &::-webkit-color-swatch {
@@ -5289,6 +5319,7 @@ const Rh = ({
5289
5319
  onClick: () => e && n && e(n),
5290
5320
  px: 1.5,
5291
5321
  py: 1,
5322
+ justify: "center",
5292
5323
  height: "37px",
5293
5324
  hoverstyle: {
5294
5325
  backgroundColor: t.palette.primary.light
@@ -5303,9 +5334,7 @@ const Rh = ({
5303
5334
  key: n.placeholder,
5304
5335
  label: n.placeholder
5305
5336
  } : void 0)
5306
- ), [i, o] = Ae(!1), [s, a] = Ae(
5307
- void 0
5308
- ), c = K(null), u = K(null), f = K(null);
5337
+ ), [i, o] = Ae(!1), [s, a] = Ae(void 0), c = K(null), u = K(null), f = K(null);
5309
5338
  Ie(() => {
5310
5339
  const p = (l) => {
5311
5340
  c.current && !c.current.contains(l.target) && o(!1);
@@ -5331,65 +5360,78 @@ const Rh = ({
5331
5360
  const d = (p) => {
5332
5361
  r(p), n.onChange && n.onChange(p), o(!1);
5333
5362
  };
5334
- return /* @__PURE__ */ O.jsxs(Te, { ref: c, direction: "column", width: "100%", justify: "start", children: [
5335
- (n.label || n.required) && /* @__PURE__ */ O.jsxs(
5336
- Te,
5337
- {
5338
- direction: "row",
5339
- gap: 0.5,
5340
- align: "center",
5341
- mb: "4px",
5342
- style: { minHeight: "1.2em" },
5343
- children: [
5344
- n.label && /* @__PURE__ */ O.jsx(kt, { size: "12", children: n.label }),
5345
- n.required && /* @__PURE__ */ O.jsx(kt, { color: e.palette.error.main, size: "12", children: "*" })
5346
- ]
5347
- }
5348
- ),
5349
- /* @__PURE__ */ O.jsxs(
5350
- Te,
5351
- {
5352
- ref: u,
5353
- elevation: 1,
5354
- onClick: () => o(!i),
5355
- style: { position: "relative", cursor: "pointer", ...n.selectOptionStyle },
5356
- children: [
5357
- n.CustomOption ? /* @__PURE__ */ O.jsx(n.CustomOption, { option: t }) : /* @__PURE__ */ O.jsx(Oa, { option: t }),
5358
- /* @__PURE__ */ O.jsx(
5359
- Te,
5360
- {
5361
- ref: f,
5362
- elevation: 1,
5363
- width: "100%",
5364
- gap: 0.5,
5365
- style: {
5366
- position: "absolute",
5367
- left: "0",
5368
- ...!n.orientation || n.orientation === "down" ? {
5369
- top: s ? `${s + 1}px` : "37px"
5370
- } : {
5371
- bottom: s ? `${s + 1}px` : "37px"
5372
- },
5373
- visibility: "hidden",
5374
- zIndex: 1,
5375
- backdropFilter: "blur(6px)",
5376
- maxHeight: "200px",
5377
- overflowY: "auto",
5378
- ...n.hideScrollbar && {
5379
- scrollbarWidth: "none",
5380
- msOverflowStyle: "none"
5381
- },
5382
- ...n.optionContainerStyle
5383
- },
5384
- children: n.options.map(
5385
- (p) => n.CustomOption ? /* @__PURE__ */ O.jsx(n.CustomOption, { option: p, handleChange: d }) : /* @__PURE__ */ O.jsx(Oa, { option: p, handleChange: d })
5363
+ return /* @__PURE__ */ O.jsxs(
5364
+ Te,
5365
+ {
5366
+ ref: c,
5367
+ direction: "column",
5368
+ width: "100%",
5369
+ justify: "start",
5370
+ children: [
5371
+ (n.label || n.required) && /* @__PURE__ */ O.jsxs(
5372
+ Te,
5373
+ {
5374
+ direction: "row",
5375
+ gap: 0.5,
5376
+ align: "center",
5377
+ mb: "4px",
5378
+ style: { minHeight: "1.2em" },
5379
+ children: [
5380
+ n.label && /* @__PURE__ */ O.jsx(kt, { size: "12", children: n.label }),
5381
+ n.required && /* @__PURE__ */ O.jsx(kt, { color: e.palette.error.main, size: "12", children: "*" })
5382
+ ]
5383
+ }
5384
+ ),
5385
+ /* @__PURE__ */ O.jsxs(
5386
+ Te,
5387
+ {
5388
+ ref: u,
5389
+ elevation: 1,
5390
+ onClick: () => o(!i),
5391
+ style: {
5392
+ position: "relative",
5393
+ cursor: "pointer",
5394
+ ...n.selectOptionStyle
5395
+ },
5396
+ children: [
5397
+ n.CustomOption ? /* @__PURE__ */ O.jsx(n.CustomOption, { option: t }) : /* @__PURE__ */ O.jsx(Oa, { option: t }),
5398
+ /* @__PURE__ */ O.jsx(
5399
+ Te,
5400
+ {
5401
+ ref: f,
5402
+ elevation: 1,
5403
+ width: "100%",
5404
+ gap: 0.5,
5405
+ style: {
5406
+ position: "absolute",
5407
+ left: "0",
5408
+ ...!n.orientation || n.orientation === "down" ? {
5409
+ top: s ? `${s + 1}px` : "37px"
5410
+ } : {
5411
+ bottom: s ? `${s + 1}px` : "37px"
5412
+ },
5413
+ visibility: "hidden",
5414
+ zIndex: 1,
5415
+ backdropFilter: "blur(6px)",
5416
+ maxHeight: "200px",
5417
+ overflowY: "auto",
5418
+ ...n.hideScrollbar && {
5419
+ scrollbarWidth: "none",
5420
+ msOverflowStyle: "none"
5421
+ },
5422
+ ...n.optionContainerStyle
5423
+ },
5424
+ children: n.options.map(
5425
+ (p) => n.CustomOption ? /* @__PURE__ */ O.jsx(n.CustomOption, { option: p, handleChange: d }) : /* @__PURE__ */ O.jsx(Oa, { option: p, handleChange: d })
5426
+ )
5427
+ }
5386
5428
  )
5387
- }
5388
- )
5389
- ]
5390
- }
5391
- )
5392
- ] });
5429
+ ]
5430
+ }
5431
+ )
5432
+ ]
5433
+ }
5434
+ );
5393
5435
  });
5394
5436
  Xd.displayName = "Select";
5395
5437
  const Vd = mt.div`
@@ -6564,10 +6606,10 @@ const Ac = Ba({
6564
6606
  }
6565
6607
  }), xh = (n) => {
6566
6608
  if (n.themes.length === 0) throw new Error("No themes provided");
6567
- const [e, t] = Ae(n.themes[0]), r = (o) => {
6568
- const s = n.themes[o];
6569
- if (!s) throw new Error("Theme not found");
6570
- t(s);
6609
+ const [e, t] = Ae(n.themes[0]), r = ({ index: o, theme: s }) => {
6610
+ const a = o ? n.themes[o] : s;
6611
+ if (!a) throw new Error("Theme not found");
6612
+ t(a);
6571
6613
  }, i = Dt(
6572
6614
  () => ({
6573
6615
  theme: e,
@@ -6660,9 +6702,11 @@ const si = (n, e) => {
6660
6702
  return n;
6661
6703
  const t = kh(n || e, 500);
6662
6704
  return {
6663
- main: t[500],
6705
+ darker: t[950],
6664
6706
  dark: t[900],
6665
- light: t[100]
6707
+ main: t[500],
6708
+ light: t[100],
6709
+ lighter: t[50]
6666
6710
  };
6667
6711
  }, $h = (n) => {
6668
6712
  const e = si(n.primary, "#000000"), t = si(n.secondary ?? "#000000", "#000000"), r = si(n.default ?? "#000000", "#000000"), i = si(n.error ?? "#e74c3c", "#e74c3c");