@gouvfr-lasuite/ui-kit 0.14.0 → 0.16.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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ButtonProps } from '@openfun/cunningham-react';
1
2
  import { Context } from 'react';
2
3
  import { CunninghamProvider as CunninghamProvider_2 } from '@openfun/cunningham-react';
3
4
  import { CursorProps } from 'react-arborist';
@@ -10,10 +11,12 @@ import { NodeApi } from 'react-arborist';
10
11
  import { NodeRendererProps } from 'react-arborist';
11
12
  import { Option as Option_2 } from '@openfun/cunningham-react';
12
13
  import { PropsWithChildren } from 'react';
14
+ import { ReactElement } from 'react';
13
15
  import { ReactNode } from 'react';
14
16
  import { SelectProps } from 'react-aria-components';
15
17
  import { SetStateAction } from 'react';
16
18
  import { TreeApi } from 'react-arborist';
19
+ import { TreeNode } from '@react-stately/data';
17
20
 
18
21
  declare type AbstractSeparatorProps = {
19
22
  withPadding?: boolean;
@@ -416,6 +419,11 @@ export declare const CunninghamProvider: (props: Parameters<typeof CunninghamPro
416
419
 
417
420
  export declare const CustomTabs: ({ tabs, defaultSelectedTab, fullWidth, }: TabsProps) => JSX.Element | null;
418
421
 
422
+ /**
423
+ * Type for custom translations - maps translation keys to their string values
424
+ */
425
+ export declare type CustomTranslations = Partial<Record<TranslationKey, string>>;
426
+
419
427
  export declare const DropdownMenu: ({ options, isOpen, onOpenChange, children, selectedValues, onSelectValue, topMessage, shouldCloseOnInteractOutside, }: PropsWithChildren<DropdownMenuProps>) => JSX.Element;
420
428
 
421
429
  export declare type DropdownMenuOption = {
@@ -440,6 +448,12 @@ export declare type DropdownMenuProps = {
440
448
  shouldCloseOnInteractOutside?: (element: Element) => boolean;
441
449
  };
442
450
 
451
+ /**
452
+ * Utility type that combines TranslationKeys with proper constraint checking.
453
+ * Use this as the main export for generating translation key types.
454
+ */
455
+ declare type ExtractTranslationKeys<T extends TranslationObject> = TranslationKeys<T>;
456
+
443
457
  export declare const Filter: (props: FilterProps) => JSX.Element;
444
458
 
445
459
  export declare type FilterOption = Option_2 & {
@@ -452,17 +466,27 @@ export declare type FilterProps = {
452
466
  options: FilterOption[];
453
467
  } & SelectProps;
454
468
 
455
- export declare const Footer: () => JSX.Element;
469
+ export declare const Footer: ({ externalLinks, legalLinks, license, logo, }: FooterProps) => JSX.Element;
470
+
471
+ export declare type FooterProps = {
472
+ externalLinks?: readonly Link[];
473
+ legalLinks?: readonly Link[];
474
+ license?: {
475
+ label: string;
476
+ link: Link;
477
+ };
478
+ logo?: {
479
+ src: string;
480
+ width?: string;
481
+ height?: string;
482
+ alt: string;
483
+ };
484
+ };
456
485
 
457
486
  export declare const getContainerSize: (iconSize: IconSize) => number;
458
487
 
459
488
  export declare const getIconSize: (iconSize: IconSize) => number;
460
489
 
461
- export declare function getLocales(): {
462
- "en-US": any;
463
- "fr-FR": any;
464
- };
465
-
466
490
  /**
467
491
  * Get a consistent avatar's color according to a hash of the name
468
492
  */
@@ -566,10 +590,23 @@ export declare const Label: ({ children, text, ...props }: LabelHTMLAttributes<H
566
590
 
567
591
  export declare const LaGaufre: () => JSX.Element;
568
592
 
569
- export declare const LanguagePicker: ({ languages }: LanguagePickerProps) => JSX.Element;
593
+ /**
594
+ * A DropdownMenu specific to languages.
595
+ *
596
+ * **Props:**
597
+ * - `languages`: The languages options (use `isChecked` attribute to set the default selected language).
598
+ * - `onChange`: A callback called when a language is selected.
599
+ * - `size`: The size of the CTA.
600
+ * - `color`: The color of the CTA.
601
+ */
602
+ export declare const LanguagePicker: ({ languages, onChange, size, color, fullWidth }: LanguagePickerProps) => JSX.Element;
570
603
 
571
604
  export declare type LanguagePickerProps = {
572
605
  languages: DropdownMenuOption[];
606
+ onChange?: (language: string) => void;
607
+ color?: ButtonProps["color"];
608
+ size?: ButtonProps["size"];
609
+ fullWidth?: ButtonProps["fullWidth"];
573
610
  };
574
611
 
575
612
  export declare const LeftPanel: ({ children, isOpen, }: PropsWithChildren<LeftPanelProps>) => JSX.Element;
@@ -578,6 +615,316 @@ export declare type LeftPanelProps = {
578
615
  isOpen?: boolean;
579
616
  };
580
617
 
618
+ declare type Link = {
619
+ label: string;
620
+ href: string;
621
+ };
622
+
623
+ export declare const locales: {
624
+ "en-US": {
625
+ components: {
626
+ "alert": {
627
+ "close_aria_label": "Delete alert";
628
+ "expand_aria_label": "Expand alert";
629
+ "shrink_aria_label": "Shrink alert";
630
+ };
631
+ "pagination": {
632
+ "goto_label": "Go to page";
633
+ "goto_label_aria": "Go to any page";
634
+ "next_aria": "Go to next page";
635
+ "previous_aria": "Go to previous page";
636
+ "goto_page_aria": "Go to page {page}";
637
+ "current_page_aria": "You are currently on page {page}";
638
+ };
639
+ "datagrid": {
640
+ "empty": "This table is empty";
641
+ "empty_alt": "Illustration of an empty table";
642
+ "loader_aria": "Loading data";
643
+ "rows_selection_aria": "All rows selection";
644
+ "row_selection_aria": "Row selection";
645
+ };
646
+ "provider": {
647
+ "test": "This is a test: {name}";
648
+ };
649
+ "forms": {
650
+ "input": {
651
+ "password": {
652
+ "show_password": "Show password";
653
+ "hide_password": "Hide password";
654
+ };
655
+ };
656
+ "select": {
657
+ "toggle_button_aria_label": "Toggle dropdown";
658
+ "clear_button_aria_label": "Clear selection";
659
+ "clear_all_button_aria_label": "Clear all selections";
660
+ "menu_empty_placeholder": "No options available";
661
+ };
662
+ "file_uploader": {
663
+ "delete_file_name": "Delete file {name}";
664
+ "delete_file": "Delete file";
665
+ "uploading": "Uploading...";
666
+ "caption": "Drag and drop or ";
667
+ "browse_files": "Browse files";
668
+ };
669
+ "date_picker": {
670
+ "toggle_button_aria_label_open": "Open calendar";
671
+ "toggle_button_aria_label_close": "Close calendar";
672
+ "clear_button_aria_label": "Clear date";
673
+ "next_month_button_aria_label": "Next month";
674
+ "next_year_button_aria_label": "Next year";
675
+ "previous_month_button_aria_label": "Previous month";
676
+ "previous_year_button_aria_label": "Previous year";
677
+ "year_select_button_aria_label": "Select a year";
678
+ "month_select_button_aria_label": "Select a month";
679
+ };
680
+ };
681
+ "modals": {
682
+ "helpers": {
683
+ "delete_confirmation": {
684
+ "title": "Are you sure?";
685
+ "children": "Are you sure to delete this item?";
686
+ "cancel": "Cancel";
687
+ "delete": "Delete";
688
+ };
689
+ "confirmation": {
690
+ "title": "Are you sure?";
691
+ "children": "Are you sure you want to do that?";
692
+ "cancel": "Cancel";
693
+ "yes": "Yes";
694
+ };
695
+ "disclaimer": {
696
+ "title": "Disclaimer";
697
+ "children": "This is a disclaimer";
698
+ "ok": "Ok";
699
+ };
700
+ };
701
+ };
702
+ };
703
+ } & {
704
+ components: {
705
+ share: {
706
+ copyLink: string;
707
+ ok: string;
708
+ shareButton: string;
709
+ modalTitle: string;
710
+ access: {
711
+ delete: string;
712
+ };
713
+ cannot_view: {
714
+ message: string;
715
+ };
716
+ invitations: {
717
+ title: string;
718
+ };
719
+ members: {
720
+ title_plural: string;
721
+ title_singular: string;
722
+ load_more: string;
723
+ };
724
+ item: {
725
+ add: string;
726
+ };
727
+ search: {
728
+ placeholder: string;
729
+ group_name: string;
730
+ };
731
+ user: {
732
+ no_result: string;
733
+ placeholder: string;
734
+ };
735
+ linkSettings: {
736
+ title: string;
737
+ reach: {
738
+ choices: {
739
+ public: {
740
+ title: string;
741
+ description: string;
742
+ };
743
+ restricted: {
744
+ title: string;
745
+ description: string;
746
+ };
747
+ };
748
+ };
749
+ role: {
750
+ choices: {
751
+ reader: {
752
+ title: string;
753
+ };
754
+ editor: {
755
+ title: string;
756
+ };
757
+ };
758
+ };
759
+ };
760
+ };
761
+ userMenu: {
762
+ open: string;
763
+ close: string;
764
+ accountSettings: string;
765
+ logout: string;
766
+ dialogTitle: string;
767
+ };
768
+ footer: {
769
+ logo: {
770
+ alt: string;
771
+ };
772
+ };
773
+ };
774
+ };
775
+ "fr-FR": {
776
+ components: {
777
+ "alert": {
778
+ "close_aria_label": "Supprimer l'alerte";
779
+ "expand_aria_label": "Ouvrir l'alerte";
780
+ "shrink_aria_label": "Fermer l'alerte";
781
+ };
782
+ "pagination": {
783
+ "goto_label": "Aller \u00E0";
784
+ "goto_label_aria": "Aller \u00E0 la page";
785
+ "next_aria": "Aller \u00E0 la page suivante";
786
+ "previous_aria": "Aller \u00E0 la page pr\u00E9c\u00E9dente";
787
+ "goto_page_aria": "Aller \u00E0 la page {page}";
788
+ "current_page_aria": "Vous \u00EAtes actuellement sur la page {page}";
789
+ };
790
+ "datagrid": {
791
+ "empty": "Ce tableau est vide";
792
+ "empty_alt": "Illustration d'un tableau vide";
793
+ "loader_aria": "Chargement des donn\u00E9es";
794
+ "rows_selection_aria": "Toutes les lignes s\u00E9lectionn\u00E9es";
795
+ "row_selection_aria": "Ligne s\u00E9lectionn\u00E9e";
796
+ };
797
+ "provider": {
798
+ "test": "Ceci est un test : {name}";
799
+ };
800
+ "forms": {
801
+ "input": {
802
+ "password": {
803
+ "show_password": "Afficher le mot de passe";
804
+ "hide_password": "Masquer le mot de passe";
805
+ };
806
+ };
807
+ "select": {
808
+ "toggle_button_aria_label": "Ouvrir le menu";
809
+ "clear_button_aria_label": "Effacer la s\u00E9lection";
810
+ "clear_all_button_aria_label": "Effacer toutes les s\u00E9lections";
811
+ "menu_empty_placeholder": "Aucun choix disponible";
812
+ };
813
+ "file_uploader": {
814
+ "delete_file_name": "Supprimer le fichier {name}";
815
+ "delete_file": "Supprimer le fichier";
816
+ "uploading": "Upload en cours ...";
817
+ "caption": "Glisser-d\u00E9poser ou ";
818
+ "browse_files": "Parcourir";
819
+ };
820
+ "date_picker": {
821
+ "toggle_button_aria_label_open": "Ouvrir le calendrier";
822
+ "toggle_button_aria_label_close": "Fermer le calendrier";
823
+ "clear_button_aria_label": "Effacer la date";
824
+ "next_month_button_aria_label": "Mois suivant";
825
+ "next_year_button_aria_label": "Ann\u00E9e suivante";
826
+ "previous_month_button_aria_label": "Mois pr\u00E9c\u00E9dent";
827
+ "previous_year_button_aria_label": "Ann\u00E9e pr\u00E9c\u00E9dente";
828
+ "year_select_button_aria_label": "S\u00E9lectionner une ann\u00E9e";
829
+ "month_select_button_aria_label": "S\u00E9lectionner un mois";
830
+ };
831
+ };
832
+ "modals": {
833
+ "helpers": {
834
+ "delete_confirmation": {
835
+ "title": "\u00CAtes-vous s\u00FBr ?";
836
+ "children": "\u00CAtes-vous s\u00FBr de vouloir supprimer cet \u00E9l\u00E9ment ?";
837
+ "cancel": "Annuler";
838
+ "delete": "Supprimer";
839
+ };
840
+ "confirmation": {
841
+ "title": "\u00CAtes-vous s\u00FBr ?";
842
+ "children": "\u00CAtes-vous s\u00FBr de vouloir faire cela ?";
843
+ "cancel": "Annuler";
844
+ "yes": "Oui";
845
+ };
846
+ "disclaimer": {
847
+ "title": "Avertissement";
848
+ "children": "Ceci est un avertissement";
849
+ "ok": "Ok";
850
+ };
851
+ };
852
+ };
853
+ };
854
+ } & {
855
+ components: {
856
+ share: {
857
+ copyLink: string;
858
+ ok: string;
859
+ modalTitle: string;
860
+ shareButton: string;
861
+ access: {
862
+ delete: string;
863
+ };
864
+ cannot_view: {
865
+ message: string;
866
+ };
867
+ invitations: {
868
+ title: string;
869
+ };
870
+ members: {
871
+ title_plural: string;
872
+ title_singular: string;
873
+ load_more: string;
874
+ };
875
+ item: {
876
+ add: string;
877
+ };
878
+ search: {
879
+ placeholder: string;
880
+ group_name: string;
881
+ };
882
+ user: {
883
+ no_result: string;
884
+ placeholder: string;
885
+ };
886
+ linkSettings: {
887
+ title: string;
888
+ reach: {
889
+ choices: {
890
+ public: {
891
+ title: string;
892
+ description: string;
893
+ };
894
+ restricted: {
895
+ title: string;
896
+ description: string;
897
+ };
898
+ };
899
+ };
900
+ role: {
901
+ choices: {
902
+ reader: {
903
+ title: string;
904
+ };
905
+ editor: {
906
+ title: string;
907
+ };
908
+ };
909
+ };
910
+ };
911
+ };
912
+ userMenu: {
913
+ open: string;
914
+ close: string;
915
+ accountSettings: string;
916
+ logout: string;
917
+ dialogTitle: string;
918
+ };
919
+ footer: {
920
+ logo: {
921
+ alt: string;
922
+ };
923
+ };
924
+ };
925
+ };
926
+ };
927
+
581
928
  export declare const MainLayout: ({ icon, children, hideLeftPanelOnDesktop, leftPanelContent, rightPanelContent, rightHeaderContent, languages, enableResize, rightPanelIsOpen, ...props }: PropsWithChildren<MainLayoutProps>) => JSX.Element;
582
929
 
583
930
  export declare type MainLayoutProps = {
@@ -700,7 +1047,7 @@ export declare type ShareMemberItemProps<UserType, AccessType> = {
700
1047
  roleTopMessage?: string;
701
1048
  };
702
1049
 
703
- export declare const ShareModal: <UserType, InvitationType, AccessType>({ searchUsersResult, children, outsideSearchContent, accesses: members, invitations, hasNextMembers, canUpdate, canView, hasNextInvitations, hideInvitations, hideMembers, cannotViewChildren, ...props }: PropsWithChildren<ShareModalProps<UserType, InvitationType, AccessType>>) => JSX.Element;
1050
+ export declare const ShareModal: <UserType, InvitationType, AccessType>({ searchUsersResult, children, outsideSearchContent, accesses: members, invitations, hasNextMembers, canUpdate, canView, hasNextInvitations, hideInvitations, hideMembers, cannotViewChildren, customTranslations, ...props }: PropsWithChildren<ShareModalProps<UserType, InvitationType, AccessType>>) => JSX.Element;
704
1051
 
705
1052
  declare type ShareModalAccessProps<UserType, AccessType> = {
706
1053
  accesses?: AccessData<UserType, AccessType>[];
@@ -756,6 +1103,7 @@ export declare type ShareModalProps<UserType, InvitationType, AccessType> = {
756
1103
  outsideSearchContent?: ReactNode;
757
1104
  hideInvitations?: boolean;
758
1105
  hideMembers?: boolean;
1106
+ customTranslations?: CustomTranslations;
759
1107
  } & ShareModalInvitationProps<UserType, InvitationType> & ShareModalAccessProps<UserType, AccessType> & ShareModalSearchProps<UserType> & ShareModalLinkSettingsProps;
760
1108
 
761
1109
  declare type ShareModalSearchProps<UserType> = {
@@ -790,6 +1138,58 @@ export declare type TabsProps = {
790
1138
  fullWidth?: boolean;
791
1139
  };
792
1140
 
1141
+ /**
1142
+ * All available translation keys extracted from the English translation file.
1143
+ * This type represents all possible keys that can be used with the translation system.
1144
+ *
1145
+ * Keys are in dot-notation format, e.g.:
1146
+ * - "components.share.copyLink"
1147
+ * - "components.share.access.delete"
1148
+ * - "components.footer.links.legal"
1149
+ */
1150
+ declare type TranslationKey = ExtractTranslationKeys<typeof locales["en-US"] | typeof locales["fr-FR"]>;
1151
+
1152
+ /**
1153
+ * Utility types for extracting all nested keys from translation objects
1154
+ * and converting them to dot-notation string literals.
1155
+ */
1156
+ /**
1157
+ * Recursively extracts all nested keys from an object type and converts them
1158
+ * to dot-notation string literals.
1159
+ *
1160
+ * @example
1161
+ * ```typescript
1162
+ * type Example = {
1163
+ * components: {
1164
+ * create: string;
1165
+ * alert: {
1166
+ * close_aria_label: string;
1167
+ * expand_aria_label: string;
1168
+ * }
1169
+ * }
1170
+ * }
1171
+ *
1172
+ * type Keys = TranslationKeys<Example>;
1173
+ * // Result: "components.create" | "components.alert.close_aria_label" | "components.alert.expand_aria_label"
1174
+ * ```
1175
+ */
1176
+ declare type TranslationKeys<T> = T extends Record<string, unknown> ? {
1177
+ [K in keyof T]: T[K] extends Record<string, unknown> ? `${K & string}.${TranslationKeys<T[K]>}` : K;
1178
+ }[keyof T] : never;
1179
+
1180
+ /**
1181
+ * Type constraint for objects that can have translation keys extracted.
1182
+ */
1183
+ declare type TranslationObject = Record<string, TranslationValue>;
1184
+
1185
+ /**
1186
+ * Helper type to define the structure of a translation object.
1187
+ * This avoids circular reference by using a more specific definition.
1188
+ */
1189
+ declare type TranslationValue = string | {
1190
+ [key: string]: TranslationValue;
1191
+ };
1192
+
793
1193
  export { TreeApi }
794
1194
 
795
1195
  export declare const TreeContext: Context<TreeContextType<any> | null>;
@@ -874,6 +1274,22 @@ export declare type TreeViewProps<T> = {
874
1274
 
875
1275
  export declare const TreeViewSeparator: ({ top, left }: CursorProps) => JSX.Element;
876
1276
 
1277
+ /**
1278
+ * Hook for using custom translations with type safety.
1279
+ *
1280
+ * This hook provides a translation function that first checks custom translations,
1281
+ * then falls back to the default Cunningham translations.
1282
+ *
1283
+ * Note: This is not a bullet proof solution, it doesn't handle variables replacement
1284
+ * as Cunningham does for now.
1285
+ *
1286
+ * @param customTranslations - Optional object mapping translation keys to custom values
1287
+ * @returns Object containing the translation function
1288
+ */
1289
+ export declare const useCustomTranslations: (customTranslations?: CustomTranslations) => {
1290
+ t: (key: TranslationKey) => string;
1291
+ };
1292
+
877
1293
  export declare const useDropdownMenu: () => {
878
1294
  isOpen: boolean;
879
1295
  setIsOpen: Dispatch<SetStateAction<boolean>>;
@@ -893,6 +1309,31 @@ export declare const useResponsive: () => {
893
1309
  isDesktop: boolean;
894
1310
  };
895
1311
 
1312
+ /**
1313
+ * User menu component.
1314
+ *
1315
+ * **Props**
1316
+ * - `user`: An object containing the user information.
1317
+ * - `settingsCTA`: A string or a function to call when the settings button is clicked.
1318
+ * - `logout`: A function to call when the logout button is clicked.
1319
+ * - `isInitialOpen`: Whether the menu should be open by default.
1320
+ * - `shouldCloseOnInteractOutside`: A function to call when the menu should be closed.
1321
+ * - `footerAction`: The child to render inside the footer.
1322
+ */
1323
+ export declare const UserMenu: ({ user, settingsCTA, logout, isInitialOpen, shouldCloseOnInteractOutside, footerAction, }: UserMenuProps) => JSX.Element | null;
1324
+
1325
+ export declare type UserMenuProps = {
1326
+ user?: {
1327
+ full_name?: string;
1328
+ email: string;
1329
+ } | null;
1330
+ settingsCTA?: string | (() => void);
1331
+ logout?: () => void;
1332
+ isInitialOpen?: boolean;
1333
+ shouldCloseOnInteractOutside?: (element: Element) => boolean;
1334
+ footerAction?: ReactElement;
1335
+ };
1336
+
896
1337
  declare type UserProps = {
897
1338
  fullName?: string;
898
1339
  email?: string;
@@ -904,7 +1345,7 @@ export declare const UserRow: ({ fullName: full_name, email, showEmail, }: UserP
904
1345
  export declare const useTree: <T>(initialItems: TreeViewDataType<T>[], refreshCallback?: (id: string) => Promise<Partial<TreeViewDataType<T>>>, loadChildrenCallback?: (id: string) => Promise<TreeViewDataType<T>[]>) => {
905
1346
  nodes: TreeDataItem<TreeViewDataType<T>>[];
906
1347
  addChild: (parentId: string | null, newNode: TreeViewDataType<T>, index?: number) => void;
907
- updateNode: (nodeId: string, updatedData: Partial<TreeViewDataType<T>>) => void;
1348
+ updateNode: (nodeId: string, updatedData: Partial<TreeViewDataType<T>>) => TreeViewDataType<T> | undefined;
908
1349
  deleteNode: (nodeId: string) => void;
909
1350
  deleteNodes: (nodeIds: string[]) => void;
910
1351
  addRootNode: (newNode: TreeViewDataType<T>, index?: number) => void;
@@ -912,7 +1353,7 @@ export declare const useTree: <T>(initialItems: TreeViewDataType<T>[], refreshCa
912
1353
  selectedNode: T | undefined;
913
1354
  setSelectedNode: Dispatch<SetStateAction<T | undefined>>;
914
1355
  refreshNode: (nodeId: string) => Promise<void>;
915
- setChildren: (parentId: string, newChildren: TreeViewDataType<T>[]) => void;
1356
+ setChildren: (parentId: string, newChildren: TreeViewDataType<T>[]) => TreeViewDataType<T> | undefined;
916
1357
  insertBeforeNode: (nodeId: string, newNode: TreeViewDataType<T>) => void;
917
1358
  insertAfterNode: (nodeId: string, newNode: TreeViewDataType<T>) => void;
918
1359
  handleMove: (result: TreeViewMoveResult) => void;
@@ -921,6 +1362,7 @@ export declare const useTree: <T>(initialItems: TreeViewDataType<T>[], refreshCa
921
1362
  appendToNode: (nodeId: string, newNode: TreeViewDataType<T>) => void;
922
1363
  move: (key: Key, toParentKey: Key | null, index: number) => void;
923
1364
  resetTree: (newItems?: TreeViewDataType<T>[]) => void;
1365
+ getItem: (key: Key) => TreeNode<TreeViewDataType<T>> | undefined;
924
1366
  handleLoadChildren: (nodeId: string) => Promise<TreeViewDataType<T>[]>;
925
1367
  selectNodeById: (nodeId: string) => void;
926
1368
  getParent: (nodeId: string) => TreeViewDataType<T> | null;