@cronos-labs/ui 0.2.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.
Files changed (63) hide show
  1. package/dist/FilterPillGroup/index.d.ts +1 -0
  2. package/dist/FilterPillGroup/index.js +1 -0
  3. package/dist/FilterPillGroup/styles.d.ts +8 -0
  4. package/dist/FilterPillGroup/styles.js +36 -0
  5. package/dist/Footer/index.d.ts +34 -0
  6. package/dist/Footer/index.js +48 -0
  7. package/dist/Footer/styles.d.ts +97 -0
  8. package/dist/Footer/styles.js +326 -0
  9. package/dist/Header/NavDropdown.d.ts +17 -0
  10. package/dist/Header/NavDropdown.js +39 -0
  11. package/dist/Header/helper.d.ts +1 -0
  12. package/dist/Header/helper.js +1 -0
  13. package/dist/Header/index.d.ts +46 -0
  14. package/dist/Header/index.js +162 -0
  15. package/dist/Header/styles.d.ts +158 -0
  16. package/dist/Header/styles.js +770 -0
  17. package/dist/LocaleSelector/index.d.ts +9 -0
  18. package/dist/LocaleSelector/index.js +62 -0
  19. package/dist/LocaleSelector/styles.d.ts +33 -0
  20. package/dist/LocaleSelector/styles.js +156 -0
  21. package/dist/SearchField/index.d.ts +14 -0
  22. package/dist/SearchField/index.js +6 -0
  23. package/dist/SearchField/styles.d.ts +20 -0
  24. package/dist/SearchField/styles.js +85 -0
  25. package/dist/SectionAnchorNav/index.d.ts +11 -0
  26. package/dist/SectionAnchorNav/index.js +41 -0
  27. package/dist/SectionAnchorNav/styles.d.ts +22 -0
  28. package/dist/SectionAnchorNav/styles.js +74 -0
  29. package/dist/Seo/index.d.ts +18 -0
  30. package/dist/Seo/index.js +53 -0
  31. package/dist/Seo/types.d.ts +4 -0
  32. package/dist/Seo/types.js +1 -0
  33. package/dist/config/eslintConfig.d.ts +6 -0
  34. package/dist/config/eslintConfig.js +31 -0
  35. package/dist/config/prettierConfig.d.ts +8 -0
  36. package/dist/config/prettierConfig.js +8 -0
  37. package/dist/format.d.ts +3 -0
  38. package/dist/format.js +9 -0
  39. package/dist/index.d.ts +21 -0
  40. package/dist/index.js +18 -0
  41. package/dist/locale/config.d.ts +5 -0
  42. package/dist/locale/config.js +103 -0
  43. package/dist/locale/hooks.d.ts +3 -0
  44. package/dist/locale/hooks.js +36 -0
  45. package/dist/locale/localePreference.d.ts +7 -0
  46. package/dist/locale/localePreference.js +21 -0
  47. package/dist/locale/localization.d.ts +11 -0
  48. package/dist/locale/localization.js +12 -0
  49. package/dist/locale/routes.d.ts +5 -0
  50. package/dist/locale/routes.js +32 -0
  51. package/dist/locale/types.d.ts +25 -0
  52. package/dist/locale/types.js +1 -0
  53. package/dist/navigationContent.d.ts +59 -0
  54. package/dist/navigationContent.js +552 -0
  55. package/dist/scrollToSectionHeading.d.ts +1 -0
  56. package/dist/scrollToSectionHeading.js +12 -0
  57. package/dist/tokens.d.ts +252 -0
  58. package/dist/tokens.js +253 -0
  59. package/dist/typography.d.ts +11 -0
  60. package/dist/typography.js +106 -0
  61. package/eslint-config.js +1 -0
  62. package/package.json +98 -0
  63. package/prettier-config.js +1 -0
@@ -0,0 +1,31 @@
1
+ import js from '@eslint/js';
2
+ import globals from 'globals';
3
+ import tseslint from 'typescript-eslint';
4
+ import reactHooks from 'eslint-plugin-react-hooks';
5
+ import reactRefresh from 'eslint-plugin-react-refresh';
6
+ import eslintConfigPrettier from 'eslint-config-prettier';
7
+ export const createReactEslintConfig = (options) => tseslint.config({
8
+ ignores: options.ignores ?? ['dist', 'coverage', 'node_modules', 'eslint.config.mjs'],
9
+ }, js.configs.recommended, ...tseslint.configs.recommendedTypeChecked, ...tseslint.configs.stylisticTypeChecked, {
10
+ languageOptions: {
11
+ ecmaVersion: 2023,
12
+ globals: {
13
+ ...globals.browser,
14
+ },
15
+ parserOptions: {
16
+ projectService: true,
17
+ allowDefaultProject: options.allowDefaultProject ?? ['*.{js,mjs,cjs,ts}'],
18
+ tsconfigRootDir: options.tsconfigRootDir,
19
+ },
20
+ },
21
+ plugins: {
22
+ 'react-hooks': reactHooks,
23
+ 'react-refresh': reactRefresh,
24
+ },
25
+ rules: {
26
+ ...reactHooks.configs.recommended.rules,
27
+ 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
28
+ '@typescript-eslint/no-explicit-any': 'error',
29
+ '@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
30
+ },
31
+ }, eslintConfigPrettier);
@@ -0,0 +1,8 @@
1
+ export declare const prettierConfig: {
2
+ readonly semi: true;
3
+ readonly singleQuote: true;
4
+ readonly jsxSingleQuote: false;
5
+ readonly trailingComma: "all";
6
+ readonly printWidth: 100;
7
+ readonly tabWidth: 2;
8
+ };
@@ -0,0 +1,8 @@
1
+ export const prettierConfig = {
2
+ semi: true,
3
+ singleQuote: true,
4
+ jsxSingleQuote: false,
5
+ trailingComma: 'all',
6
+ printWidth: 100,
7
+ tabWidth: 2,
8
+ };
@@ -0,0 +1,3 @@
1
+ type MessageFormatValues = Record<string, string | number>;
2
+ export declare const interpolateMessageTemplate: (template: string, values: MessageFormatValues) => string;
3
+ export {};
package/dist/format.js ADDED
@@ -0,0 +1,9 @@
1
+ export const interpolateMessageTemplate = (template, values) => {
2
+ return template.replace(/\{(\w+)\}/g, (match, key) => {
3
+ const value = values[key];
4
+ if (value === undefined) {
5
+ return match;
6
+ }
7
+ return String(value);
8
+ });
9
+ };
@@ -0,0 +1,21 @@
1
+ export { tokens, desktopViewportQuery } from './tokens.js';
2
+ export * from './typography.js';
3
+ export { Locale } from './locale/localization.js';
4
+ export type { AppLocale, LocaleConfig, LocaleDefinition, LocalePrefixStrategy, TextDirection, LocalizedContentDictionary, LocalizedPageMetadata, } from './locale/types.js';
5
+ export { localeConfig } from './locale/config.js';
6
+ export { isSupportedLocale, resolveLocale, stripLocalePrefix, buildLocalizedPath, } from './locale/routes.js';
7
+ export { useCurrentLocale, useApplyLocaleDocumentAttributes } from './locale/hooks.js';
8
+ export { setStoredLocalePreference, getStoredLocalePreference, hasStoredLocalePreference, localePreferenceStorageKey, } from './locale/localePreference.js';
9
+ export type { SeoMeta } from './Seo/types.js';
10
+ export { Seo, type RouteSeoMeta } from './Seo/index.js';
11
+ export { LocaleSelector } from './LocaleSelector/index.js';
12
+ export { Header, type HeaderPresentationVariant, type HeaderPresentationState, type HeaderNavChild, type HeaderNavItem, type HeaderContent, type HeaderWaitlistCta, } from './Header/index.js';
13
+ export { normalizePathname } from './Header/helper.js';
14
+ export { Footer, type FooterLinkItem, type FooterLinkGroup, type FooterLegalLinkItem, type FooterContent, } from './Footer/index.js';
15
+ export { navigationContent } from './navigationContent.js';
16
+ export type { NavigationContent } from './navigationContent.js';
17
+ export { interpolateMessageTemplate } from './format.js';
18
+ export { SectionAnchorNav, type SectionAnchorNavItem } from './SectionAnchorNav/index.js';
19
+ export { scrollToSectionHeading } from './scrollToSectionHeading.js';
20
+ export { PillButton, FilterPillRow } from './FilterPillGroup/index.js';
21
+ export { SearchField, type SearchFieldProps } from './SearchField/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ export { tokens, desktopViewportQuery } from './tokens.js';
2
+ export * from './typography.js';
3
+ export { Locale } from './locale/localization.js';
4
+ export { localeConfig } from './locale/config.js';
5
+ export { isSupportedLocale, resolveLocale, stripLocalePrefix, buildLocalizedPath, } from './locale/routes.js';
6
+ export { useCurrentLocale, useApplyLocaleDocumentAttributes } from './locale/hooks.js';
7
+ export { setStoredLocalePreference, getStoredLocalePreference, hasStoredLocalePreference, localePreferenceStorageKey, } from './locale/localePreference.js';
8
+ export { Seo } from './Seo/index.js';
9
+ export { LocaleSelector } from './LocaleSelector/index.js';
10
+ export { Header, } from './Header/index.js';
11
+ export { normalizePathname } from './Header/helper.js';
12
+ export { Footer, } from './Footer/index.js';
13
+ export { navigationContent } from './navigationContent.js';
14
+ export { interpolateMessageTemplate } from './format.js';
15
+ export { SectionAnchorNav } from './SectionAnchorNav/index.js';
16
+ export { scrollToSectionHeading } from './scrollToSectionHeading.js';
17
+ export { PillButton, FilterPillRow } from './FilterPillGroup/index.js';
18
+ export { SearchField } from './SearchField/index.js';
@@ -0,0 +1,5 @@
1
+ import type { AppLocale, LocaleConfig } from './types.js';
2
+ export declare const DEFAULT_LOCALE: AppLocale;
3
+ export declare const FALLBACK_LOCALE: AppLocale;
4
+ export declare const SUPPORTED_LOCALES: AppLocale[];
5
+ export declare const localeConfig: LocaleConfig;
@@ -0,0 +1,103 @@
1
+ import { Locale } from './localization.js';
2
+ export const DEFAULT_LOCALE = Locale.English;
3
+ export const FALLBACK_LOCALE = Locale.English;
4
+ export const SUPPORTED_LOCALES = [
5
+ Locale.English,
6
+ Locale.Indonesian,
7
+ Locale.Portuguese,
8
+ Locale.EnglishPhilippines,
9
+ Locale.Vietnamese,
10
+ Locale.EnglishNigeria,
11
+ Locale.SpanishMexico,
12
+ Locale.EnglishIndia,
13
+ Locale.Korean,
14
+ ];
15
+ export const localeConfig = {
16
+ defaultLocale: DEFAULT_LOCALE,
17
+ fallbackLocale: FALLBACK_LOCALE,
18
+ supportedLocales: SUPPORTED_LOCALES,
19
+ localePrefixStrategy: 'as-needed',
20
+ locales: {
21
+ [Locale.English]: {
22
+ code: Locale.English,
23
+ label: 'English',
24
+ selectorLabel: 'Global (English)',
25
+ formatLocale: 'en-US',
26
+ textDirection: 'ltr',
27
+ pathPrefix: Locale.English,
28
+ isDefault: true,
29
+ },
30
+ [Locale.EnglishIndia]: {
31
+ code: Locale.EnglishIndia,
32
+ label: 'English (India)',
33
+ selectorLabel: 'India (English)',
34
+ formatLocale: 'en-IN',
35
+ textDirection: 'ltr',
36
+ pathPrefix: Locale.EnglishIndia,
37
+ isDefault: false,
38
+ },
39
+ [Locale.EnglishNigeria]: {
40
+ code: Locale.EnglishNigeria,
41
+ label: 'English (Nigeria)',
42
+ selectorLabel: 'Nigeria (English)',
43
+ formatLocale: 'en-NG',
44
+ textDirection: 'ltr',
45
+ pathPrefix: Locale.EnglishNigeria,
46
+ isDefault: false,
47
+ },
48
+ [Locale.EnglishPhilippines]: {
49
+ code: Locale.EnglishPhilippines,
50
+ label: 'English (Philippines)',
51
+ selectorLabel: 'Philippines (English)',
52
+ formatLocale: 'en-PH',
53
+ textDirection: 'ltr',
54
+ pathPrefix: Locale.EnglishPhilippines,
55
+ isDefault: false,
56
+ },
57
+ [Locale.Portuguese]: {
58
+ code: Locale.Portuguese,
59
+ label: 'Portuguese (Brazil)',
60
+ selectorLabel: 'Brasil (Português)',
61
+ formatLocale: 'pt-BR',
62
+ textDirection: 'ltr',
63
+ pathPrefix: Locale.Portuguese,
64
+ isDefault: false,
65
+ },
66
+ [Locale.Indonesian]: {
67
+ code: Locale.Indonesian,
68
+ label: 'Indonesian (Indonesia)',
69
+ selectorLabel: 'Indonesia (Bahasa Indonesia)',
70
+ formatLocale: 'id-ID',
71
+ textDirection: 'ltr',
72
+ pathPrefix: Locale.Indonesian,
73
+ isDefault: false,
74
+ },
75
+ [Locale.Korean]: {
76
+ code: Locale.Korean,
77
+ label: 'Korean (South Korea)',
78
+ selectorLabel: '대한민국 (한국어)',
79
+ formatLocale: 'ko-KR',
80
+ textDirection: 'ltr',
81
+ pathPrefix: Locale.Korean,
82
+ isDefault: false,
83
+ },
84
+ [Locale.SpanishMexico]: {
85
+ code: Locale.SpanishMexico,
86
+ label: 'Spanish (Mexico)',
87
+ selectorLabel: 'México (Español)',
88
+ formatLocale: 'es-MX',
89
+ textDirection: 'ltr',
90
+ pathPrefix: Locale.SpanishMexico,
91
+ isDefault: false,
92
+ },
93
+ [Locale.Vietnamese]: {
94
+ code: Locale.Vietnamese,
95
+ label: 'Vietnamese (Vietnam)',
96
+ selectorLabel: 'Việt Nam (Tiếng Việt)',
97
+ formatLocale: 'vi-VN',
98
+ textDirection: 'ltr',
99
+ pathPrefix: Locale.Vietnamese,
100
+ isDefault: false,
101
+ },
102
+ },
103
+ };
@@ -0,0 +1,3 @@
1
+ import type { AppLocale } from './types.js';
2
+ export declare const useCurrentLocale: () => AppLocale;
3
+ export declare const useApplyLocaleDocumentAttributes: () => void;
@@ -0,0 +1,36 @@
1
+ import { useEffect } from 'react';
2
+ import { useLocation, useNavigate, useParams } from 'react-router-dom';
3
+ import { localeConfig } from './config.js';
4
+ import { getStoredLocalePreference, hasStoredLocalePreference, setStoredLocalePreference, } from './localePreference.js';
5
+ import { buildLocalizedPath, resolveLocale, stripLocalePrefix } from './routes.js';
6
+ export const useCurrentLocale = () => {
7
+ const { locale } = useParams();
8
+ return resolveLocale(locale);
9
+ };
10
+ export const useApplyLocaleDocumentAttributes = () => {
11
+ const locale = useCurrentLocale();
12
+ const location = useLocation();
13
+ const navigate = useNavigate();
14
+ const { locale: routeLocale } = useParams();
15
+ useEffect(() => {
16
+ const storedLocale = getStoredLocalePreference();
17
+ if (storedLocale === null || storedLocale === locale) {
18
+ return;
19
+ }
20
+ const canonicalPathname = routeLocale === locale ? stripLocalePrefix(location.pathname) : location.pathname;
21
+ void navigate({
22
+ pathname: buildLocalizedPath(canonicalPathname, storedLocale),
23
+ search: location.search,
24
+ hash: location.hash,
25
+ }, { replace: true });
26
+ }, [locale, location.hash, location.pathname, location.search, navigate, routeLocale]);
27
+ useEffect(() => {
28
+ document.documentElement.lang = localeConfig.locales[locale].formatLocale;
29
+ document.documentElement.dir = localeConfig.locales[locale].textDirection;
30
+ }, [locale, location.pathname]);
31
+ useEffect(() => {
32
+ if (routeLocale === locale && !hasStoredLocalePreference()) {
33
+ setStoredLocalePreference(locale);
34
+ }
35
+ }, [locale, routeLocale]);
36
+ };
@@ -0,0 +1,7 @@
1
+ import type { AppLocale } from './types.js';
2
+ export declare const localePreferenceStorageKey = "cronos.locale";
3
+ type StoredLocalePreference = AppLocale | null;
4
+ export declare const setStoredLocalePreference: (locale: AppLocale) => void;
5
+ export declare const getStoredLocalePreference: () => StoredLocalePreference;
6
+ export declare const hasStoredLocalePreference: () => boolean;
7
+ export {};
@@ -0,0 +1,21 @@
1
+ import { isSupportedLocale } from './routes.js';
2
+ export const localePreferenceStorageKey = 'cronos.locale';
3
+ const getLocaleStorage = () => {
4
+ if (typeof window === 'undefined' || window.localStorage === undefined)
5
+ return null;
6
+ return window.localStorage;
7
+ };
8
+ export const setStoredLocalePreference = (locale) => {
9
+ const localeStorage = getLocaleStorage();
10
+ if (localeStorage === null)
11
+ return;
12
+ localeStorage.setItem(localePreferenceStorageKey, locale);
13
+ };
14
+ export const getStoredLocalePreference = () => {
15
+ const localeStorage = getLocaleStorage();
16
+ if (localeStorage === null)
17
+ return null;
18
+ const storedLocale = localeStorage.getItem(localePreferenceStorageKey);
19
+ return isSupportedLocale(storedLocale) ? storedLocale : null;
20
+ };
21
+ export const hasStoredLocalePreference = () => getStoredLocalePreference() !== null;
@@ -0,0 +1,11 @@
1
+ export declare enum Locale {
2
+ English = "en",
3
+ EnglishIndia = "en-in",
4
+ EnglishNigeria = "en-ng",
5
+ EnglishPhilippines = "en-ph",
6
+ Indonesian = "id-id",
7
+ Korean = "ko-kr",
8
+ Portuguese = "pt-br",
9
+ SpanishMexico = "es-mx",
10
+ Vietnamese = "vi-vn"
11
+ }
@@ -0,0 +1,12 @@
1
+ export var Locale;
2
+ (function (Locale) {
3
+ Locale["English"] = "en";
4
+ Locale["EnglishIndia"] = "en-in";
5
+ Locale["EnglishNigeria"] = "en-ng";
6
+ Locale["EnglishPhilippines"] = "en-ph";
7
+ Locale["Indonesian"] = "id-id";
8
+ Locale["Korean"] = "ko-kr";
9
+ Locale["Portuguese"] = "pt-br";
10
+ Locale["SpanishMexico"] = "es-mx";
11
+ Locale["Vietnamese"] = "vi-vn";
12
+ })(Locale || (Locale = {}));
@@ -0,0 +1,5 @@
1
+ import type { AppLocale } from './types.js';
2
+ export declare const isSupportedLocale: (value: string | null | undefined) => value is AppLocale;
3
+ export declare const resolveLocale: (value: string | undefined) => AppLocale;
4
+ export declare const stripLocalePrefix: (pathname: string) => string;
5
+ export declare const buildLocalizedPath: (path: string, locale: AppLocale) => string;
@@ -0,0 +1,32 @@
1
+ import { localeConfig } from './config.js';
2
+ export const isSupportedLocale = (value) => {
3
+ if (!value) {
4
+ return false;
5
+ }
6
+ return localeConfig.supportedLocales.includes(value);
7
+ };
8
+ export const resolveLocale = (value) => {
9
+ if (isSupportedLocale(value)) {
10
+ return value;
11
+ }
12
+ return localeConfig.fallbackLocale;
13
+ };
14
+ export const stripLocalePrefix = (pathname) => {
15
+ const [, possibleLocale, ...remainingSegments] = pathname.split('/');
16
+ if (!isSupportedLocale(possibleLocale)) {
17
+ return pathname;
18
+ }
19
+ if (remainingSegments.length === 0) {
20
+ return '/';
21
+ }
22
+ return `/${remainingSegments.join('/')}`;
23
+ };
24
+ export const buildLocalizedPath = (path, locale) => {
25
+ if (locale === localeConfig.defaultLocale) {
26
+ return path;
27
+ }
28
+ if (path === '/') {
29
+ return `/${locale}`;
30
+ }
31
+ return `/${locale}${path}`;
32
+ };
@@ -0,0 +1,25 @@
1
+ import type { SeoMeta } from '../Seo/types.js';
2
+ import type { Locale } from './localization.js';
3
+ export type AppLocale = Locale.English | Locale.EnglishIndia | Locale.EnglishNigeria | Locale.EnglishPhilippines | Locale.Indonesian | Locale.Korean | Locale.Portuguese | Locale.SpanishMexico | Locale.Vietnamese;
4
+ export type LocalePrefixStrategy = 'as-needed';
5
+ export type TextDirection = 'ltr' | 'rtl';
6
+ export interface LocaleDefinition {
7
+ code: AppLocale;
8
+ label: string;
9
+ selectorLabel: string;
10
+ formatLocale: string;
11
+ textDirection: TextDirection;
12
+ pathPrefix: string;
13
+ isDefault: boolean;
14
+ }
15
+ export interface LocaleConfig {
16
+ defaultLocale: AppLocale;
17
+ fallbackLocale: AppLocale;
18
+ supportedLocales: AppLocale[];
19
+ localePrefixStrategy: LocalePrefixStrategy;
20
+ locales: Record<AppLocale, LocaleDefinition>;
21
+ }
22
+ export type LocalizedContentDictionary<T> = Record<AppLocale, T>;
23
+ export interface LocalizedPageMetadata extends SeoMeta {
24
+ locale: AppLocale;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import type { LocalizedContentDictionary } from './locale/types.js';
2
+ export interface NavigationContent {
3
+ header: {
4
+ about: string;
5
+ learn: string;
6
+ deposit: string;
7
+ desktop: string;
8
+ joinWaitlist: string;
9
+ waitlistEmailCta: string;
10
+ soon: string;
11
+ localeSelectorAriaLabel: string;
12
+ };
13
+ footer: {
14
+ ctaTitle: string;
15
+ emailPlaceholder: string;
16
+ submitLabel: string;
17
+ consentLabel: string;
18
+ consentNote: string;
19
+ socialHeading: string;
20
+ copyrightText: string;
21
+ legalNavLabel: string;
22
+ disclaimer: string[];
23
+ groups: {
24
+ cronos: string;
25
+ resources: string;
26
+ developers: string;
27
+ };
28
+ links: {
29
+ deposit: string;
30
+ learn: string;
31
+ brand: string;
32
+ newsletter: string;
33
+ evmDocumentation: string;
34
+ posDocumentation: string;
35
+ cronosEcosystem: string;
36
+ legalTermsPdf: string;
37
+ termsConditionsPdf: string;
38
+ appTermsConditions: string;
39
+ cookiePreferences: string;
40
+ };
41
+ socialLinks: {
42
+ discord: string;
43
+ instagram: string;
44
+ linkedin: string;
45
+ telegram: string;
46
+ tiktok: string;
47
+ x: string;
48
+ youtube: string;
49
+ };
50
+ waitlistForm: {
51
+ successMessage: string;
52
+ emptyEmailMessage: string;
53
+ invalidEmailMessage: string;
54
+ errorMessage: string;
55
+ submittingLabel: string;
56
+ };
57
+ };
58
+ }
59
+ export declare const navigationContent: LocalizedContentDictionary<NavigationContent>;