@inf-monkeys-tech/monkeys-design 0.4.36 → 0.4.37

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.js CHANGED
@@ -20373,6 +20373,265 @@ registerTheme(
20373
20373
  version: "1.0.0"
20374
20374
  }
20375
20375
  );
20376
+ var LOGIN_LOGO_POSITIONS = ["top", "middle", "bottom"];
20377
+ var normalizeCssValue = (value) => {
20378
+ const trimmed = value?.trim();
20379
+ return trimmed || void 0;
20380
+ };
20381
+ var createBackgroundImage = (gradient, imageUrl) => {
20382
+ const resolvedGradient = normalizeCssValue(gradient);
20383
+ const resolvedImageUrl = normalizeCssValue(imageUrl);
20384
+ return [resolvedGradient, resolvedImageUrl ? `url(${JSON.stringify(resolvedImageUrl)})` : void 0].filter(Boolean).join(", ");
20385
+ };
20386
+ var normalizeLogoPosition = (position) => position && LOGIN_LOGO_POSITIONS.includes(position) ? position : "bottom";
20387
+ var normalizeLogoScale = (scale) => typeof scale === "number" && Number.isFinite(scale) && scale > 0 ? scale : void 0;
20388
+ function LoginPage({
20389
+ className,
20390
+ style,
20391
+ background,
20392
+ logo,
20393
+ primaryColor,
20394
+ radius,
20395
+ customCss,
20396
+ toolbar,
20397
+ title,
20398
+ backAction,
20399
+ methods,
20400
+ activeMethodId,
20401
+ defaultMethodId,
20402
+ onMethodChange,
20403
+ externalLabel,
20404
+ externalMethods = [],
20405
+ callout
20406
+ }) {
20407
+ const availableMethods = React.useMemo(() => methods.filter((method) => !method.hidden), [methods]);
20408
+ const fallbackMethodId = defaultMethodId ?? availableMethods[0]?.id;
20409
+ const [internalMethodId, setInternalMethodId] = React.useState(fallbackMethodId);
20410
+ const currentMethodId = activeMethodId ?? internalMethodId;
20411
+ const activeMethod = availableMethods.find((method) => method.id === currentMethodId) ?? availableMethods[0];
20412
+ const hasTabs = availableMethods.length > 1;
20413
+ const backgroundImage = createBackgroundImage(background?.gradient, background?.imageUrl);
20414
+ const backgroundMode = backgroundImage ? "custom" : "default";
20415
+ const logoPosition = normalizeLogoPosition(logo?.position);
20416
+ const logoScale = normalizeLogoScale(logo?.scale);
20417
+ React.useEffect(() => {
20418
+ if (!availableMethods.length) {
20419
+ setInternalMethodId(void 0);
20420
+ return;
20421
+ }
20422
+ if (!currentMethodId || !availableMethods.some((method) => method.id === currentMethodId)) {
20423
+ setInternalMethodId(fallbackMethodId ?? availableMethods[0]?.id);
20424
+ }
20425
+ }, [availableMethods, currentMethodId, fallbackMethodId]);
20426
+ const rootStyle = React.useMemo(
20427
+ () => ({
20428
+ ...primaryColor ? { ["--login-page-theme-primary-color"]: primaryColor } : null,
20429
+ ...radius ? { ["--login-page-theme-radius"]: radius } : null,
20430
+ ...style
20431
+ }),
20432
+ [primaryColor, radius, style]
20433
+ );
20434
+ const handleMethodChange = (methodId) => {
20435
+ if (activeMethodId === void 0) {
20436
+ setInternalMethodId(methodId);
20437
+ }
20438
+ onMethodChange?.(methodId);
20439
+ };
20440
+ const renderExternalMethod = (method) => {
20441
+ const button = /* @__PURE__ */ jsxRuntime.jsxs(
20442
+ "button",
20443
+ {
20444
+ type: "button",
20445
+ className: "login-page__oauth-button",
20446
+ "data-login-part": "external-button",
20447
+ "data-login-method-id": method.id,
20448
+ onClick: method.onClick,
20449
+ disabled: method.disabled,
20450
+ children: [
20451
+ method.icon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "login-page__oauth-icon", "data-login-part": "external-icon", children: method.icon }) : null,
20452
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: method.label })
20453
+ ]
20454
+ }
20455
+ );
20456
+ return /* @__PURE__ */ jsxRuntime.jsx(React__default.default.Fragment, { children: method.render ? method.render(button) : button }, method.id);
20457
+ };
20458
+ return /* @__PURE__ */ jsxRuntime.jsxs(
20459
+ "main",
20460
+ {
20461
+ className: ["login-page", className].filter(Boolean).join(" "),
20462
+ "data-login-page": true,
20463
+ "data-login-part": "root",
20464
+ "data-login-background": backgroundMode,
20465
+ style: rootStyle,
20466
+ children: [
20467
+ customCss ? /* @__PURE__ */ jsxRuntime.jsx("style", { "data-login-page-custom-css": true, children: customCss }) : null,
20468
+ /* @__PURE__ */ jsxRuntime.jsx(
20469
+ "div",
20470
+ {
20471
+ className: "login-page__background",
20472
+ "data-login-part": "background",
20473
+ "data-login-background": backgroundMode,
20474
+ style: backgroundImage ? { backgroundImage } : void 0,
20475
+ "aria-hidden": "true"
20476
+ }
20477
+ ),
20478
+ toolbar ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "login-page__toolbar", "data-login-part": "toolbar", children: toolbar }) : null,
20479
+ logo?.url ? /* @__PURE__ */ jsxRuntime.jsx(
20480
+ "div",
20481
+ {
20482
+ className: `login-page__logo login-page__logo--${logoPosition}`,
20483
+ "data-login-part": "logo",
20484
+ "data-logo-position": logoPosition,
20485
+ children: /* @__PURE__ */ jsxRuntime.jsx(
20486
+ "img",
20487
+ {
20488
+ className: "login-page__logo-image",
20489
+ "data-login-part": "logo-image",
20490
+ src: logo.url,
20491
+ alt: logo.alt ?? "",
20492
+ style: logoScale ? { transform: `scale(${logoScale})` } : void 0
20493
+ }
20494
+ )
20495
+ }
20496
+ ) : null,
20497
+ /* @__PURE__ */ jsxRuntime.jsxs(
20498
+ "section",
20499
+ {
20500
+ className: "login-page__form",
20501
+ "data-login-part": "panel",
20502
+ "aria-label": typeof title === "string" ? title : void 0,
20503
+ children: [
20504
+ backAction ? /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "login-page__back", "data-login-part": "back", onClick: backAction.onClick, children: [
20505
+ backAction.icon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "login-page__back-icon", "data-login-part": "back-icon", children: backAction.icon }) : null,
20506
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: backAction.label })
20507
+ ] }) : null,
20508
+ title ? /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "login-page__title", "data-login-part": "title", children: title }) : null,
20509
+ hasTabs ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "login-page__tabs", "data-login-part": "tabs", role: "tablist", children: availableMethods.map((method) => {
20510
+ const selected = method.id === activeMethod?.id;
20511
+ return /* @__PURE__ */ jsxRuntime.jsxs(
20512
+ "button",
20513
+ {
20514
+ type: "button",
20515
+ role: "tab",
20516
+ "aria-selected": selected,
20517
+ className: `login-page__tab ${selected ? "login-page__tab--active" : ""}`,
20518
+ "data-login-part": "tab",
20519
+ "data-login-method-id": method.id,
20520
+ "data-active": selected ? "true" : "false",
20521
+ onClick: () => handleMethodChange(method.id),
20522
+ children: [
20523
+ method.icon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "login-page__tab-icon", "data-login-part": "tab-icon", children: method.icon }) : null,
20524
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: method.label })
20525
+ ]
20526
+ },
20527
+ method.id
20528
+ );
20529
+ }) }) : null,
20530
+ activeMethod ? /* @__PURE__ */ jsxRuntime.jsxs(
20531
+ "form",
20532
+ {
20533
+ className: "login-page__form-fields",
20534
+ "data-login-part": "form",
20535
+ "data-login-method-id": activeMethod.id,
20536
+ onSubmit: activeMethod.onSubmit,
20537
+ children: [
20538
+ activeMethod.fields.map((field) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "login-page__field", "data-login-part": "field", "data-login-field-name": field.name, children: /* @__PURE__ */ jsxRuntime.jsx(
20539
+ "input",
20540
+ {
20541
+ id: field.id,
20542
+ name: field.name,
20543
+ type: field.type ?? "text",
20544
+ value: field.value,
20545
+ placeholder: field.placeholder,
20546
+ autoComplete: field.autoComplete,
20547
+ inputMode: field.inputMode,
20548
+ maxLength: field.maxLength,
20549
+ pattern: field.pattern,
20550
+ disabled: activeMethod.disabled || activeMethod.isLoading || field.disabled,
20551
+ required: field.required,
20552
+ className: "login-page__input",
20553
+ "data-login-part": "input",
20554
+ onChange: (event) => field.onChange(event.target.value)
20555
+ }
20556
+ ) }, field.name)),
20557
+ activeMethod.checkbox ? /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "login-page__remember", "data-login-part": "checkbox-label", htmlFor: activeMethod.checkbox.id, children: [
20558
+ /* @__PURE__ */ jsxRuntime.jsx(
20559
+ "input",
20560
+ {
20561
+ id: activeMethod.checkbox.id,
20562
+ type: "checkbox",
20563
+ className: "login-page__checkbox",
20564
+ "data-login-part": "checkbox",
20565
+ checked: activeMethod.checkbox.checked,
20566
+ disabled: activeMethod.disabled || activeMethod.isLoading || activeMethod.checkbox.disabled,
20567
+ onChange: (event) => activeMethod.checkbox?.onChange(event.target.checked)
20568
+ }
20569
+ ),
20570
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: activeMethod.checkbox.label })
20571
+ ] }) : null,
20572
+ activeMethod.footer || activeMethod.footerAction ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "login-page__method-footer", "data-login-part": "method-footer", children: [
20573
+ activeMethod.footer,
20574
+ activeMethod.footerAction ? /* @__PURE__ */ jsxRuntime.jsx(
20575
+ "button",
20576
+ {
20577
+ type: "button",
20578
+ className: "login-page__method-footer-action",
20579
+ "data-login-part": "method-footer-action",
20580
+ "data-login-method-id": activeMethod.id,
20581
+ onClick: activeMethod.footerAction.onClick,
20582
+ disabled: activeMethod.disabled || activeMethod.isLoading || activeMethod.footerAction.disabled,
20583
+ children: activeMethod.footerAction.label
20584
+ }
20585
+ ) : null
20586
+ ] }) : null,
20587
+ /* @__PURE__ */ jsxRuntime.jsx(
20588
+ "button",
20589
+ {
20590
+ type: "submit",
20591
+ className: "login-page__submit",
20592
+ "data-login-part": "submit-button",
20593
+ disabled: activeMethod.disabled || activeMethod.isLoading,
20594
+ children: activeMethod.isLoading && activeMethod.loadingLabel ? activeMethod.loadingLabel : activeMethod.submitLabel
20595
+ }
20596
+ )
20597
+ ]
20598
+ }
20599
+ ) : null,
20600
+ callout ? /* @__PURE__ */ jsxRuntime.jsxs(
20601
+ "div",
20602
+ {
20603
+ className: `login-page__callout login-page__callout--${callout.tone ?? "info"}`,
20604
+ "data-login-part": "callout",
20605
+ "data-tone": callout.tone ?? "info",
20606
+ children: [
20607
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "login-page__callout-title", "data-login-part": "callout-title", children: callout.title }),
20608
+ callout.description ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "login-page__callout-description", "data-login-part": "callout-description", children: callout.description }) : null,
20609
+ callout.detail ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "login-page__callout-detail", "data-login-part": "callout-detail", children: callout.detail }) : null,
20610
+ callout.action ? /* @__PURE__ */ jsxRuntime.jsx(
20611
+ "button",
20612
+ {
20613
+ type: "button",
20614
+ className: "login-page__callout-action",
20615
+ "data-login-part": "callout-action",
20616
+ onClick: callout.action.onClick,
20617
+ disabled: callout.action.disabled,
20618
+ children: callout.action.label
20619
+ }
20620
+ ) : null
20621
+ ]
20622
+ }
20623
+ ) : null,
20624
+ externalMethods.length ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "login-page__oauth-section", "data-login-part": "external-methods", children: [
20625
+ externalLabel ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "login-page__oauth-label", "data-login-part": "external-label", children: externalLabel }) : null,
20626
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "login-page__oauth-list", "data-login-part": "external-list", children: externalMethods.map(renderExternalMethod) })
20627
+ ] }) : null
20628
+ ]
20629
+ }
20630
+ )
20631
+ ]
20632
+ }
20633
+ );
20634
+ }
20376
20635
  var containerStyle = {
20377
20636
  display: "flex",
20378
20637
  alignItems: "center",
@@ -25251,6 +25510,7 @@ exports.InteractiveTableEditableTextCell = InteractiveTableEditableTextCell;
25251
25510
  exports.InteractiveTableReadonlyCell = InteractiveTableReadonlyCell;
25252
25511
  exports.InteractiveTableSelectCell = InteractiveTableSelectCell;
25253
25512
  exports.LoginLayout = LoginLayout;
25513
+ exports.LoginPage = LoginPage;
25254
25514
  exports.MonkeysToastProvider = MonkeysToastProvider;
25255
25515
  exports.MonkeysToaster = MonkeysToaster;
25256
25516
  exports.NavButton = NavButton;