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