cynx-lib 1.3.83 → 1.3.84

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cynx-lib",
3
- "version": "1.3.83",
3
+ "version": "1.3.84",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -12,6 +12,24 @@ export default function Layout({
12
12
  user,
13
13
  onLogout,
14
14
  onLock,
15
+ // Footer customization & actions
16
+ footerActions,
17
+ extraFooterActions,
18
+ footerSlot,
19
+ lockLabel,
20
+ logoutLabel,
21
+ lockTitle,
22
+ logoutTitle,
23
+ lockIcon,
24
+ logoutIcon,
25
+ showLock,
26
+ showLogout,
27
+ userSlot,
28
+ renderUser,
29
+ footerStyle,
30
+ footerClassName,
31
+ footerActionsLayout,
32
+ footerActionsStyle,
15
33
  collapsible = true,
16
34
  isCollapsed,
17
35
  onToggleCollapse,
@@ -38,6 +56,7 @@ export default function Layout({
38
56
  contentStyle = {},
39
57
  contentClassName,
40
58
  children,
59
+ ...restProps
41
60
  }) {
42
61
  return (
43
62
  <div
@@ -59,6 +78,23 @@ export default function Layout({
59
78
  user={user}
60
79
  onLogout={onLogout}
61
80
  onLock={onLock}
81
+ footerActions={footerActions}
82
+ extraFooterActions={extraFooterActions}
83
+ footerSlot={footerSlot}
84
+ lockLabel={lockLabel}
85
+ logoutLabel={logoutLabel}
86
+ lockTitle={lockTitle}
87
+ logoutTitle={logoutTitle}
88
+ lockIcon={lockIcon}
89
+ logoutIcon={logoutIcon}
90
+ showLock={showLock}
91
+ showLogout={showLogout}
92
+ userSlot={userSlot}
93
+ renderUser={renderUser}
94
+ footerStyle={footerStyle}
95
+ footerClassName={footerClassName}
96
+ footerActionsLayout={footerActionsLayout}
97
+ footerActionsStyle={footerActionsStyle}
62
98
  collapsible={collapsible}
63
99
  isCollapsed={isCollapsed}
64
100
  onToggleCollapse={onToggleCollapse}
@@ -75,6 +111,7 @@ export default function Layout({
75
111
  activeSubColor={activeSubColor}
76
112
  subItemsIndent={subItemsIndent}
77
113
  hasPermission={hasPermission}
114
+ {...restProps}
78
115
  />
79
116
 
80
117
  {/* Main Content Area */}
@@ -102,6 +102,23 @@ export default function Sidebar({
102
102
  user,
103
103
  onLogout,
104
104
  onLock,
105
+ // Footer customization & actions
106
+ footerActions,
107
+ extraFooterActions,
108
+ lockLabel = 'Блок',
109
+ logoutLabel = 'Выйти',
110
+ lockTitle,
111
+ logoutTitle,
112
+ lockIcon,
113
+ logoutIcon,
114
+ showLock = true,
115
+ showLogout = true,
116
+ userSlot,
117
+ renderUser,
118
+ footerStyle = {},
119
+ footerClassName = '',
120
+ footerActionsLayout = 'flex',
121
+ footerActionsStyle = {},
105
122
  collapsible = true,
106
123
  isCollapsed: controlledIsCollapsed,
107
124
  defaultCollapsed = false,
@@ -260,6 +277,70 @@ export default function Sidebar({
260
277
  ? 'var(--sidebar-text-muted, rgba(255, 255, 255, 0.45))'
261
278
  : 'var(--sidebar-text-muted, var(--t3, #a1a1aa))';
262
279
 
280
+ // Default footer actions (Lock / Logout)
281
+ const defaultActions = [];
282
+
283
+ if (onLock && showLock) {
284
+ defaultActions.push({
285
+ id: 'lock',
286
+ label: lockLabel,
287
+ title: lockTitle || (typeof lockLabel === 'string' ? lockLabel : 'Заблокировать'),
288
+ icon: lockIcon || (isCollapsed ? <Lock size={16} /> : <Lock size={13} />),
289
+ onClick: onLock,
290
+ variant: isDarkSidebar ? 'secondary' : 'ghost',
291
+ style: isDarkSidebar
292
+ ? {
293
+ background: 'rgba(255,255,255,0.08)',
294
+ color: 'rgba(255,255,255,0.85)',
295
+ borderColor: 'rgba(255,255,255,0.12)',
296
+ }
297
+ : {},
298
+ });
299
+ }
300
+
301
+ if (onLogout && showLogout) {
302
+ defaultActions.push({
303
+ id: 'logout',
304
+ label: logoutLabel,
305
+ title:
306
+ logoutTitle ||
307
+ (user?.username || user?.fullName
308
+ ? `${typeof logoutLabel === 'string' ? logoutLabel : 'Выйти'} (${user?.username || user?.fullName})`
309
+ : typeof logoutLabel === 'string'
310
+ ? logoutLabel
311
+ : 'Выйти'),
312
+ icon: logoutIcon || (isCollapsed ? <LogOut size={17} /> : <LogOut size={14} />),
313
+ onClick: onLogout,
314
+ variant: 'ghost',
315
+ danger: true,
316
+ style: isDarkSidebar
317
+ ? {
318
+ background: 'rgba(239, 68, 68, 0.1)',
319
+ borderColor: 'rgba(239, 68, 68, 0.2)',
320
+ }
321
+ : {},
322
+ });
323
+ }
324
+
325
+ // Resolve final actions list
326
+ let resolvedActions;
327
+ if (typeof footerActions === 'function') {
328
+ resolvedActions = footerActions(defaultActions, { isCollapsed, user, isDarkSidebar });
329
+ } else if (Array.isArray(footerActions)) {
330
+ resolvedActions = footerActions;
331
+ } else {
332
+ resolvedActions = [...defaultActions];
333
+ if (Array.isArray(extraFooterActions) && extraFooterActions.length > 0) {
334
+ resolvedActions.push(...extraFooterActions);
335
+ }
336
+ }
337
+
338
+ const finalActions = (resolvedActions || []).filter(
339
+ (act) => act && !act.hidden && act.visible !== false
340
+ );
341
+
342
+ const hasFooterContent = Boolean(user || finalActions.length > 0 || userSlot || renderUser);
343
+
263
344
  return (
264
345
  <aside
265
346
  className={sidebarClassName}
@@ -659,158 +740,243 @@ export default function Sidebar({
659
740
 
660
741
  {/* Footer Slot or Default User Profile / Actions */}
661
742
  {footerSlot ? (
662
- footerSlot
663
- ) : user ? (
743
+ typeof footerSlot === 'function'
744
+ ? footerSlot({ isCollapsed, user, actions: finalActions, isDarkSidebar })
745
+ : footerSlot
746
+ ) : hasFooterContent ? (
664
747
  <div
748
+ className={footerClassName}
665
749
  style={{
666
750
  padding: isCollapsed ? '12px 8px' : 12,
667
751
  borderTop: effectiveSidebarBorder,
668
752
  flexShrink: 0,
753
+ ...footerStyle,
669
754
  }}
670
755
  >
671
756
  {!isCollapsed ? (
672
757
  <>
673
- <div
674
- style={{
675
- fontSize: '.72rem',
676
- color: userFullNameColor,
677
- marginBottom: 8,
678
- padding: '0 8px',
679
- whiteSpace: 'nowrap',
680
- overflow: 'hidden',
681
- textOverflow: 'ellipsis',
682
- }}
683
- >
684
- {user.fullName ? (
685
- <>
686
- {user.fullName}{' '}
687
- {user.username && (
688
- <span style={{ color: userUsernameColor }}>({user.username})</span>
689
- )}
690
- </>
758
+ {userSlot ? (
759
+ typeof userSlot === 'function' ? (
760
+ userSlot({ user, isCollapsed: false, isDarkSidebar })
691
761
  ) : (
692
- user.username
693
- )}
694
- </div>
695
-
696
- <div style={{ display: 'flex', gap: 6 }}>
697
- {onLock && (
698
- <Button
699
- variant={isDarkSidebar ? 'secondary' : 'ghost'}
700
- size="md"
701
- onClick={onLock}
702
- icon={<Lock size={13} />}
703
- title="Заблокировать"
704
- style={{
705
- flex: 1,
706
- justifyContent: 'center',
707
- ...(isDarkSidebar
708
- ? {
709
- background: 'rgba(255,255,255,0.08)',
710
- color: 'rgba(255,255,255,0.85)',
711
- borderColor: 'rgba(255,255,255,0.12)',
712
- }
713
- : {}),
714
- }}
715
- >
716
- Блок
717
- </Button>
718
- )}
719
-
720
- {onLogout && (
721
- <Button
722
- variant="ghost"
723
- size="md"
724
- onClick={onLogout}
725
- icon={<LogOut size={14} />}
726
- title="Выйти"
727
- style={{
728
- width: onLock ? 'auto' : '100%',
729
- flex: onLock ? 1 : undefined,
730
- justifyContent: 'center',
731
- color: isDarkSidebar ? '#f87171' : 'var(--danger, #ef4444)',
732
- ...(isDarkSidebar
733
- ? {
734
- background: 'rgba(239, 68, 68, 0.1)',
735
- borderColor: 'rgba(239, 68, 68, 0.2)',
736
- }
737
- : {}),
738
- }}
739
- >
740
- Выйти
741
- </Button>
742
- )}
743
- </div>
744
- </>
745
- ) : (
746
- <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 6 }}>
747
- {onLock && (
748
- <button
749
- type="button"
750
- onClick={onLock}
751
- title="Заблокировать экран"
762
+ userSlot
763
+ )
764
+ ) : renderUser ? (
765
+ renderUser({ user, isCollapsed: false, isDarkSidebar })
766
+ ) : user ? (
767
+ <div
752
768
  style={{
753
- width: 36,
754
- height: 36,
755
- display: 'flex',
756
- alignItems: 'center',
757
- justifyContent: 'center',
758
- background: 'transparent',
759
- border: 'none',
760
- borderRadius: 'var(--rads, 8px)',
761
- color: isDarkSidebar ? 'rgba(255,255,255,0.7)' : 'var(--t2, #71717a)',
762
- cursor: 'pointer',
763
- transition: 'all .14s',
764
- }}
765
- onMouseEnter={(e) => {
766
- e.currentTarget.style.background = isDarkSidebar
767
- ? 'rgba(255,255,255,0.08)'
768
- : 'var(--grey-1, #fafafa)';
769
- e.currentTarget.style.color = isDarkSidebar
770
- ? '#ffffff'
771
- : 'var(--primary-text, #09090b)';
772
- }}
773
- onMouseLeave={(e) => {
774
- e.currentTarget.style.background = 'transparent';
775
- e.currentTarget.style.color = isDarkSidebar
776
- ? 'rgba(255,255,255,0.7)'
777
- : 'var(--t2, #71717a)';
769
+ fontSize: '.72rem',
770
+ color: userFullNameColor,
771
+ marginBottom: 8,
772
+ padding: '0 8px',
773
+ whiteSpace: 'nowrap',
774
+ overflow: 'hidden',
775
+ textOverflow: 'ellipsis',
778
776
  }}
779
777
  >
780
- <Lock size={16} />
781
- </button>
782
- )}
778
+ {user.fullName ? (
779
+ <>
780
+ {user.fullName}{' '}
781
+ {user.username && (
782
+ <span style={{ color: userUsernameColor }}>({user.username})</span>
783
+ )}
784
+ </>
785
+ ) : (
786
+ user.username
787
+ )}
788
+ </div>
789
+ ) : null}
783
790
 
784
- {onLogout && (
785
- <button
786
- type="button"
787
- onClick={onLogout}
788
- title={`Выйти (${user?.username || user?.fullName || ''})`}
791
+ {finalActions.length > 0 && (
792
+ <div
789
793
  style={{
790
- width: 36,
791
- height: 36,
792
- display: 'flex',
793
- alignItems: 'center',
794
- justifyContent: 'center',
795
- background: 'transparent',
796
- border: 'none',
797
- borderRadius: 'var(--rads, 8px)',
798
- color: isDarkSidebar ? '#f87171' : 'var(--danger, #ef4444)',
799
- cursor: 'pointer',
800
- transition: 'all .14s',
801
- }}
802
- onMouseEnter={(e) => {
803
- e.currentTarget.style.background = isDarkSidebar
804
- ? 'rgba(239,68,68,0.2)'
805
- : 'var(--danger-bg, rgba(239,68,68,.10))';
806
- }}
807
- onMouseLeave={(e) => {
808
- e.currentTarget.style.background = 'transparent';
794
+ ...(footerActionsLayout === 'column'
795
+ ? { display: 'flex', flexDirection: 'column', gap: 6, width: '100%' }
796
+ : footerActionsLayout === 'grid'
797
+ ? {
798
+ display: 'grid',
799
+ gridTemplateColumns: `repeat(${finalActions.length > 2 ? 2 : finalActions.length}, minmax(0, 1fr))`,
800
+ gap: 6,
801
+ width: '100%',
802
+ }
803
+ : {
804
+ display: 'flex',
805
+ gap: 6,
806
+ flexWrap: 'wrap',
807
+ width: '100%',
808
+ }),
809
+ ...footerActionsStyle,
809
810
  }}
810
811
  >
811
- <LogOut size={17} />
812
- </button>
812
+ {finalActions.map((act, index) => {
813
+ const key = act.id || act.key || index;
814
+ if (act.render) {
815
+ return (
816
+ <React.Fragment key={key}>
817
+ {act.render({ action: act, isCollapsed: false, isDarkSidebar, user })}
818
+ </React.Fragment>
819
+ );
820
+ }
821
+
822
+ const isDanger = Boolean(act.danger || act.variant === 'danger');
823
+ const actionLabel =
824
+ act.label !== undefined
825
+ ? act.label
826
+ : act.text !== undefined
827
+ ? act.text
828
+ : act.title;
829
+ const actionTitle =
830
+ act.title || (typeof actionLabel === 'string' ? actionLabel : undefined);
831
+ const isSingle = finalActions.length === 1;
832
+
833
+ return (
834
+ <Button
835
+ key={key}
836
+ variant={
837
+ act.variant || (isDanger ? 'ghost' : isDarkSidebar ? 'secondary' : 'ghost')
838
+ }
839
+ size={act.size || 'md'}
840
+ onClick={act.onClick}
841
+ disabled={act.disabled}
842
+ icon={act.icon}
843
+ title={actionTitle}
844
+ className={act.className || ''}
845
+ style={{
846
+ flex: act.flex !== undefined ? act.flex : 1,
847
+ width: isSingle ? '100%' : (act.width || 'auto'),
848
+ justifyContent: act.justifyContent || 'center',
849
+ minWidth: 0,
850
+ whiteSpace: 'nowrap',
851
+ ...(isDanger
852
+ ? {
853
+ color: isDarkSidebar ? '#f87171' : 'var(--danger, #ef4444)',
854
+ ...(isDarkSidebar
855
+ ? {
856
+ background: 'rgba(239, 68, 68, 0.1)',
857
+ borderColor: 'rgba(239, 68, 68, 0.2)',
858
+ }
859
+ : {}),
860
+ }
861
+ : isDarkSidebar &&
862
+ (!act.variant || act.variant === 'secondary' || act.variant === 'ghost')
863
+ ? {
864
+ background: 'rgba(255,255,255,0.08)',
865
+ color: 'rgba(255,255,255,0.85)',
866
+ borderColor: 'rgba(255,255,255,0.12)',
867
+ }
868
+ : {}),
869
+ ...act.style,
870
+ }}
871
+ >
872
+ {actionLabel}
873
+ </Button>
874
+ );
875
+ })}
876
+ </div>
813
877
  )}
878
+ </>
879
+ ) : (
880
+ <div
881
+ style={{
882
+ display: 'flex',
883
+ flexDirection: 'column',
884
+ alignItems: 'center',
885
+ gap: 6,
886
+ width: '100%',
887
+ }}
888
+ >
889
+ {userSlot &&
890
+ typeof userSlot === 'function' &&
891
+ userSlot({ user, isCollapsed: true, isDarkSidebar })}
892
+ {renderUser && renderUser({ user, isCollapsed: true, isDarkSidebar })}
893
+ {finalActions.map((act, index) => {
894
+ const key = act.id || act.key || index;
895
+ if (act.render) {
896
+ return (
897
+ <React.Fragment key={key}>
898
+ {act.render({ action: act, isCollapsed: true, isDarkSidebar, user })}
899
+ </React.Fragment>
900
+ );
901
+ }
902
+
903
+ const isDanger = Boolean(act.danger || act.variant === 'danger');
904
+ const actionLabel =
905
+ act.label !== undefined
906
+ ? act.label
907
+ : act.text !== undefined
908
+ ? act.text
909
+ : act.title;
910
+ const actionTitle =
911
+ act.title || (typeof actionLabel === 'string' ? actionLabel : undefined);
912
+ const actionIcon =
913
+ act.collapsedIcon ||
914
+ act.icon ||
915
+ (typeof actionLabel === 'string' ? actionLabel.slice(0, 2) : null);
916
+
917
+ const normalColor = isDanger
918
+ ? isDarkSidebar
919
+ ? '#f87171'
920
+ : 'var(--danger, #ef4444)'
921
+ : isDarkSidebar
922
+ ? 'rgba(255,255,255,0.7)'
923
+ : 'var(--t2, #71717a)';
924
+
925
+ const hoverBg = isDanger
926
+ ? isDarkSidebar
927
+ ? 'rgba(239,68,68,0.2)'
928
+ : 'var(--danger-bg, rgba(239,68,68,.10))'
929
+ : isDarkSidebar
930
+ ? 'rgba(255,255,255,0.08)'
931
+ : 'var(--grey-1, #fafafa)';
932
+
933
+ const hoverColor = isDanger
934
+ ? isDarkSidebar
935
+ ? '#fca5a5'
936
+ : 'var(--danger, #ef4444)'
937
+ : isDarkSidebar
938
+ ? '#ffffff'
939
+ : 'var(--primary-text, #09090b)';
940
+
941
+ return (
942
+ <button
943
+ key={key}
944
+ type="button"
945
+ onClick={act.onClick}
946
+ disabled={act.disabled}
947
+ title={actionTitle}
948
+ aria-label={actionTitle}
949
+ className={act.className || ''}
950
+ style={{
951
+ width: 36,
952
+ height: 36,
953
+ display: 'flex',
954
+ alignItems: 'center',
955
+ justifyContent: 'center',
956
+ background: 'transparent',
957
+ border: 'none',
958
+ borderRadius: 'var(--rads, 8px)',
959
+ color: normalColor,
960
+ cursor: act.disabled ? 'not-allowed' : 'pointer',
961
+ opacity: act.disabled ? 0.5 : 1,
962
+ transition: 'all .14s',
963
+ ...act.collapsedStyle,
964
+ ...act.style,
965
+ }}
966
+ onMouseEnter={(e) => {
967
+ if (act.disabled) return;
968
+ e.currentTarget.style.background = hoverBg;
969
+ e.currentTarget.style.color = hoverColor;
970
+ }}
971
+ onMouseLeave={(e) => {
972
+ e.currentTarget.style.background = 'transparent';
973
+ e.currentTarget.style.color = normalColor;
974
+ }}
975
+ >
976
+ {actionIcon}
977
+ </button>
978
+ );
979
+ })}
814
980
  </div>
815
981
  )}
816
982
  </div>