@rolster/react-components 19.9.0 → 19.10.0

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.
@@ -1472,6 +1472,132 @@ function RlsAlertComponent({ bordered, children, icon, identifier, rlsTheme }) {
1472
1472
  }
1473
1473
  const RlsAlert = require$$0.memo(RlsAlertComponent);
1474
1474
 
1475
+ const APP_THEME_ATTRIBUTE = 'app-theme';
1476
+ function getAppTheme() {
1477
+ if (typeof document === 'undefined') {
1478
+ return 'light';
1479
+ }
1480
+ const theme = document.body.getAttribute(APP_THEME_ATTRIBUTE);
1481
+ return theme === 'dark' || theme === 'dim' ? theme : 'light';
1482
+ }
1483
+ function setAppTheme(theme) {
1484
+ if (typeof document === 'undefined') {
1485
+ return;
1486
+ }
1487
+ document.body.setAttribute(APP_THEME_ATTRIBUTE, theme);
1488
+ }
1489
+ function toggleAppTheme() {
1490
+ const theme = getAppTheme() === 'dark' ? 'light' : 'dark';
1491
+ setAppTheme(theme);
1492
+ return theme;
1493
+ }
1494
+
1495
+ const reactI18n = i18n.i18n({
1496
+ es: {
1497
+ appThemeDark: 'Oscuro',
1498
+ appThemeDim: 'Intermedio',
1499
+ appThemeLight: 'Claro',
1500
+ confirmationActionApproved: 'Aceptar',
1501
+ dateActionCancel: 'Cancelar',
1502
+ dateActionSelect: 'Establecer',
1503
+ dateActionToday: 'Hoy',
1504
+ chooserImageActionCancel: 'Cancelar',
1505
+ editorImageActionRestore: 'Restaurar',
1506
+ editorImageActionSelect: 'Seleccionar',
1507
+ listEmptyDescription: 'Lo sentimos, en el momento no hay elementos en el listado',
1508
+ listEmptyTitle: 'Selección no disponible',
1509
+ listInputPlaceholder: 'Escriba palabre clave para filtrar...'
1510
+ },
1511
+ en: {
1512
+ appThemeDark: 'Dark',
1513
+ appThemeDim: 'Dim',
1514
+ appThemeLight: 'Light',
1515
+ confirmationActionApproved: 'Approved',
1516
+ dateActionCancel: 'Cancel',
1517
+ dateActionSelect: 'Select',
1518
+ dateActionToday: 'Today',
1519
+ chooserImageActionCancel: 'Cancel',
1520
+ editorImageActionRestore: 'Restore',
1521
+ editorImageActionSelect: 'Select',
1522
+ listEmptyDescription: 'Sorry, there are currently no items in the list',
1523
+ listEmptyTitle: 'Selection not available',
1524
+ listInputPlaceholder: 'Enter keyword to filter...'
1525
+ }
1526
+ });
1527
+
1528
+ function RlsTab({ disabled, onSelect, tab, value }) {
1529
+ const className = renderClassStatus('rls-tabs__children', {
1530
+ active: tab.value === value,
1531
+ disabled: disabled || tab.disabled
1532
+ });
1533
+ const onClick = require$$0.useCallback(() => {
1534
+ if (!disabled && !tab.disabled) {
1535
+ onSelect(tab.value);
1536
+ }
1537
+ }, [disabled, tab.disabled, onSelect]);
1538
+ return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsx("span", { children: tab.label }) }));
1539
+ }
1540
+ function RlsTabsComponent({ tabs, formControl, onValue, value, rlsTheme }) {
1541
+ const [valueInternal, setValueInternal] = require$$0.useState();
1542
+ const valueSelected = require$$0.useMemo(() => {
1543
+ return formControl ? formControl.value : valueInternal;
1544
+ }, [formControl?.value, valueInternal]);
1545
+ const onSelect = require$$0.useCallback((value) => {
1546
+ if (formControl) {
1547
+ formControl?.setValue(value);
1548
+ }
1549
+ else {
1550
+ setValueInternal(value);
1551
+ }
1552
+ onValue?.(value);
1553
+ }, [formControl, onValue]);
1554
+ require$$0.useEffect(() => {
1555
+ if (formControl?.value !== undefined) {
1556
+ return setValueInternal(formControl.value);
1557
+ }
1558
+ if (value !== undefined) {
1559
+ return setValueInternal(value);
1560
+ }
1561
+ const initial = tabs.find((tab) => tab.defaultActive) ?? tabs[0];
1562
+ if (initial) {
1563
+ onSelect(initial.value);
1564
+ }
1565
+ }, [value, formControl?.value]);
1566
+ return (jsxRuntimeExports.jsx("div", { className: "rls-tabs", "rls-theme": rlsTheme, children: tabs.map((tab, index) => {
1567
+ return (jsxRuntimeExports.jsx(RlsTab, { tab: tab, disabled: formControl?.disabled, value: valueSelected, onSelect: onSelect }, index));
1568
+ }) }));
1569
+ }
1570
+ const RlsTabs = require$$0.memo(RlsTabsComponent);
1571
+
1572
+ const APP_THEMES = ['light', 'dim', 'dark'];
1573
+ const LABELS = {
1574
+ light: () => reactI18n('appThemeLight'),
1575
+ dim: () => reactI18n('appThemeDim'),
1576
+ dark: () => reactI18n('appThemeDark')
1577
+ };
1578
+ function RlsAppThemeTabsComponent({ labels, onValue, rlsTheme, themes = APP_THEMES, value }) {
1579
+ const [appTheme, setAppThemeValue] = require$$0.useState(() => value ?? getAppTheme());
1580
+ require$$0.useEffect(() => {
1581
+ if (value !== undefined) {
1582
+ setAppTheme(value);
1583
+ setAppThemeValue(value);
1584
+ }
1585
+ }, [value]);
1586
+ const tabs = require$$0.useMemo(() => {
1587
+ return themes.map((theme) => ({
1588
+ label: labels?.[theme] ?? LABELS[theme](),
1589
+ value: theme
1590
+ }));
1591
+ }, [labels, themes]);
1592
+ const onSelect = require$$0.useCallback((theme) => {
1593
+ setAppTheme(theme);
1594
+ setAppThemeValue(theme);
1595
+ onValue?.(theme);
1596
+ }, [onValue]);
1597
+ return (jsxRuntimeExports.jsx(RlsTabs, { tabs: tabs, value: appTheme, onValue: onSelect, rlsTheme: rlsTheme }));
1598
+ }
1599
+ const RlsAppThemeTabs = require$$0.memo(RlsAppThemeTabsComponent);
1600
+
1475
1601
  function RlsBallotComponent({ bordered, className, children, img, initials, skeleton, subtitle, rlsTheme }) {
1476
1602
  const classNameBallot = renderClassStatus('rls-ballot', { bordered, skeleton }, className);
1477
1603
  return (jsxRuntimeExports.jsxs("div", { className: classNameBallot, "rls-theme": rlsTheme, children: [(img || initials) && (jsxRuntimeExports.jsxs(RlsAvatar, { skeleton: skeleton, children: [img && jsxRuntimeExports.jsx("img", { src: img }), initials && jsxRuntimeExports.jsx("span", { children: initials })] })), jsxRuntimeExports.jsxs("div", { className: "rls-ballot__component", children: [jsxRuntimeExports.jsx("div", { className: "rls-ballot__title", children: jsxRuntimeExports.jsx(RlsSkeletonText, { active: skeleton, children: children }) }), subtitle && (jsxRuntimeExports.jsx("div", { className: "rls-ballot__subtitle", children: jsxRuntimeExports.jsx(RlsSkeletonText, { active: skeleton, children: subtitle }) }))] })] }));
@@ -1759,33 +1885,6 @@ function RlsFieldFileComponent({ accept, children, disabled: _disabled, formCont
1759
1885
  }
1760
1886
  const RlsFieldFile = require$$0.memo(RlsFieldFileComponent);
1761
1887
 
1762
- const reactI18n = i18n.i18n({
1763
- es: {
1764
- confirmationActionApproved: 'Aceptar',
1765
- dateActionCancel: 'Cancelar',
1766
- dateActionSelect: 'Establecer',
1767
- dateActionToday: 'Hoy',
1768
- chooserImageActionCancel: 'Cancelar',
1769
- editorImageActionRestore: 'Restaurar',
1770
- editorImageActionSelect: 'Seleccionar',
1771
- listEmptyDescription: 'Lo sentimos, en el momento no hay elementos en el listado',
1772
- listEmptyTitle: 'Selección no disponible',
1773
- listInputPlaceholder: 'Escriba palabre clave para filtrar...'
1774
- },
1775
- en: {
1776
- confirmationActionApproved: 'Approved',
1777
- dateActionCancel: 'Cancel',
1778
- dateActionSelect: 'Select',
1779
- dateActionToday: 'Today',
1780
- chooserImageActionCancel: 'Cancel',
1781
- editorImageActionRestore: 'Restore',
1782
- editorImageActionSelect: 'Select',
1783
- listEmptyDescription: 'Sorry, there are currently no items in the list',
1784
- listEmptyTitle: 'Selection not available',
1785
- listInputPlaceholder: 'Enter keyword to filter...'
1786
- }
1787
- });
1788
-
1789
1888
  function useEventCallback(callback) {
1790
1889
  const refCallback = require$$0.useRef(callback);
1791
1890
  require$$0.useInsertionEffect(() => {
@@ -2696,50 +2795,6 @@ function RlsSliderComponent({ children, className, disabled, formControl, identi
2696
2795
  }
2697
2796
  const RlsSlider = require$$0.memo(RlsSliderComponent);
2698
2797
 
2699
- function RlsTab({ disabled, onSelect, tab, value }) {
2700
- const className = renderClassStatus('rls-tabs__children', {
2701
- active: tab.value === value,
2702
- disabled: disabled || tab.disabled
2703
- });
2704
- const onClick = require$$0.useCallback(() => {
2705
- if (!disabled && !tab.disabled) {
2706
- onSelect(tab.value);
2707
- }
2708
- }, [disabled, tab.disabled, onSelect]);
2709
- return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsx("span", { children: tab.label }) }));
2710
- }
2711
- function RlsTabsComponent({ tabs, formControl, onValue, value, rlsTheme }) {
2712
- const [valueInternal, setValueInternal] = require$$0.useState();
2713
- const valueSelected = require$$0.useMemo(() => {
2714
- return formControl ? formControl.value : valueInternal;
2715
- }, [formControl?.value, valueInternal]);
2716
- const onSelect = require$$0.useCallback((value) => {
2717
- if (formControl) {
2718
- formControl?.setValue(value);
2719
- }
2720
- else {
2721
- setValueInternal(value);
2722
- }
2723
- onValue?.(value);
2724
- }, [formControl, onValue]);
2725
- require$$0.useEffect(() => {
2726
- if (formControl?.value !== undefined) {
2727
- return setValueInternal(formControl.value);
2728
- }
2729
- if (value !== undefined) {
2730
- return setValueInternal(value);
2731
- }
2732
- const initial = tabs.find((tab) => tab.defaultActive) ?? tabs[0];
2733
- if (initial) {
2734
- onSelect(initial.value);
2735
- }
2736
- }, [value, formControl?.value]);
2737
- return (jsxRuntimeExports.jsx("div", { className: "rls-tabs", "rls-theme": rlsTheme, children: tabs.map((tab, index) => {
2738
- return (jsxRuntimeExports.jsx(RlsTab, { tab: tab, disabled: formControl?.disabled, value: valueSelected, onSelect: onSelect }, index));
2739
- }) }));
2740
- }
2741
- const RlsTabs = require$$0.memo(RlsTabsComponent);
2742
-
2743
2798
  function RlsToolbarComponent({ actions, children, subtitle }) {
2744
2799
  return (jsxRuntimeExports.jsxs("div", { className: "rls-toolbar", children: [jsxRuntimeExports.jsxs("div", { className: "rls-toolbar__description", children: [children && jsxRuntimeExports.jsx("label", { className: "rls-toolbar__title", children: children }), subtitle && (jsxRuntimeExports.jsx("label", { className: "rls-toolbar__subtitle smalltext-semibold", children: subtitle }))] }), actions && (jsxRuntimeExports.jsx("div", { className: "rls-toolbar__actions", children: actions.map((action, index) => (jsxRuntimeExports.jsx("div", { children: action }, index))) }))] }));
2745
2800
  }
@@ -5224,6 +5279,24 @@ function RlsApplication({ children }) {
5224
5279
  return (jsxRuntimeExports.jsxs(RlsContext, { value: state, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children, jsxRuntimeExports.jsx(RlsSnackbar, {})] }), jsxRuntimeExports.jsx(RlsConfirmation, {}), jsxRuntimeExports.jsx(RlsNotifications, {})] }));
5225
5280
  }
5226
5281
 
5282
+ function useAppThemeController(initialTheme, primaryTheme = 'light', secondaryTheme = 'dark') {
5283
+ const [appTheme, setAppThemeValue] = require$$0.useState(() => {
5284
+ if (initialTheme) {
5285
+ setAppTheme(initialTheme);
5286
+ return initialTheme;
5287
+ }
5288
+ return getAppTheme();
5289
+ });
5290
+ const setValue = require$$0.useCallback((value) => {
5291
+ setAppTheme(value);
5292
+ setAppThemeValue(value);
5293
+ }, []);
5294
+ const toggle = require$$0.useCallback(() => {
5295
+ setValue(appTheme === primaryTheme ? secondaryTheme : primaryTheme);
5296
+ }, [appTheme, primaryTheme, secondaryTheme, setValue]);
5297
+ return { setValue, toggle, value: appTheme };
5298
+ }
5299
+
5227
5300
  const DEFAULT_DESIGN_SYSTEM = 'bordered';
5228
5301
 
5229
5302
  const DESIGN_SYSTEM_PREFIX = 'rls-design-system';
@@ -5357,32 +5430,13 @@ function useTabsController(options) {
5357
5430
  return require$$0.useMemo(() => ({ Tabs, formControl }), [Tabs, formControl]);
5358
5431
  }
5359
5432
 
5360
- const APP_THEME_ATTRIBUTE = 'app-theme';
5361
- function getAppTheme() {
5362
- if (typeof document === 'undefined') {
5363
- return 'light';
5364
- }
5365
- return document.body.getAttribute(APP_THEME_ATTRIBUTE) === 'dark'
5366
- ? 'dark'
5367
- : 'light';
5368
- }
5369
- function setAppTheme(theme) {
5370
- if (typeof document === 'undefined') {
5371
- return;
5372
- }
5373
- document.body.setAttribute(APP_THEME_ATTRIBUTE, theme);
5374
- }
5375
- function toggleAppTheme() {
5376
- const theme = getAppTheme() === 'dark' ? 'light' : 'dark';
5377
- setAppTheme(theme);
5378
- return theme;
5379
- }
5380
-
5433
+ exports.APP_THEMES = APP_THEMES;
5381
5434
  exports.ConfirmationResult = ConfirmationResult;
5382
5435
  exports.DEFAULT_COLOR = DEFAULT_COLOR;
5383
5436
  exports.RlsAccordion = RlsAccordion;
5384
5437
  exports.RlsAlert = RlsAlert;
5385
5438
  exports.RlsAmount = RlsAmount;
5439
+ exports.RlsAppThemeTabs = RlsAppThemeTabs;
5386
5440
  exports.RlsApplication = RlsApplication;
5387
5441
  exports.RlsAreaText = RlsAreaText;
5388
5442
  exports.RlsAvatar = RlsAvatar;
@@ -5516,6 +5570,7 @@ exports.setDesignSystem = setDesignSystem;
5516
5570
  exports.setErrorsI18n = setErrorsI18n;
5517
5571
  exports.setThemeColor = setThemeColor;
5518
5572
  exports.toggleAppTheme = toggleAppTheme;
5573
+ exports.useAppThemeController = useAppThemeController;
5519
5574
  exports.useConfirmation = useConfirmation;
5520
5575
  exports.useDatatable = useDatatable;
5521
5576
  exports.useDesingSystemController = useDesingSystemController;