Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/components/Assets/Flags/system/Flag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@
import { IconSize } from '@/components/Icon/types';
import { FlagName } from './types';
export type { FlagName, SVGAssetProps } from './types';
import { resolveFlagName, DeprecatedFlagName } from './retroactiveNames';
import FlagsLight from './FlagsLight';
import FlagsDark from './FlagsDark';
import { SvgImageElement } from '@/components/commonElement';
import type { ThemeName } from '@/theme';
import { type ThemeName, THEMES } from '@/theme';
import {
createAssetResolver,
type AssetAlias,
type AssetDeprecatedName,
} from '@/components/Assets/config';

const resolveFlagName = createAssetResolver<FlagName>();

export { resolveFlagName };

Check warning on line 18 in src/components/Assets/Flags/system/Flag.tsx

View workflow job for this annotation

GitHub Actions / code-quality-checks

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components

export interface FlagProps extends SVGAttributes<SVGElement> {
name: FlagName | DeprecatedFlagName;
// TODO: The Light and dark theme should not be hard typed
// once https://github.com/ClickHouse/click-ui/pull/784
// is merged, update it
theme?: 'light' | 'dark';
name: FlagName | AssetAlias | AssetDeprecatedName;
theme?: ThemeName;
size?: IconSize;
}

const Flag = ({ name, theme, size, ...props }: FlagProps) => {
const { name: themeName } = useTheme();
const resolvedName = resolveFlagName(name);
const resolvedTheme: ThemeName = theme ?? (themeName as ThemeName) ?? 'light';
const resolvedTheme: ThemeName = theme ?? (themeName as ThemeName) ?? THEMES.Light;
const Component =
resolvedTheme === 'light' ? FlagsLight[resolvedName] : FlagsDark[resolvedName];
resolvedTheme === THEMES.Dark ? FlagsLight[resolvedName] : FlagsDark[resolvedName];

if (!Component) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Assets/Flags/system/FlagsDark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { FlagName } from './types';
import type { SVGAssetProps } from '../../types';
import type { ComponentType } from 'react';

const FlagsLight: Record<FlagName, ComponentType<SVGAssetProps>> = {
const FlagsDark: Record<FlagName, ComponentType<SVGAssetProps>> = {
australia: Australia,
brazil: Brazil,
canada: Canada,
Expand All @@ -54,4 +54,4 @@ const FlagsLight: Record<FlagName, ComponentType<SVGAssetProps>> = {
'united-states': United_States,
};

export default FlagsLight;
export default FlagsDark;
7 changes: 5 additions & 2 deletions src/components/Assets/Flags/system/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export { Flag, type FlagProps } from './Flag';
export {
Flag,
type FlagProps,
resolveFlagName,
} from './Flag';
export { default as FlagsLight } from './FlagsLight';
export { default as FlagsDark } from './FlagsDark';
export type { FlagName } from './types';
export type { SVGAssetProps } from '../../types';
export { resolveFlagName, type DeprecatedFlagName } from './retroactiveNames';
63 changes: 0 additions & 63 deletions src/components/Assets/Flags/system/retroactiveNames.ts

This file was deleted.

20 changes: 14 additions & 6 deletions src/components/Assets/Icons/system/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@
import { useTheme } from 'styled-components';
import { IconSize } from '@/components/Icon/types';
import { IconName } from './types';
import { resolveIconName, DeprecatedIconName } from './retroactiveNames';
import IconsLight from './IconsLight';
import IconsDark from './IconsDark';
import { SvgImageElement } from '@/components/commonElement';
import type { ThemeName } from '@/theme';
import { type ThemeName, THEMES } from '@/theme';
import {
createAssetResolver,
type AssetAlias,
type AssetDeprecatedName,
} from '@/components/Assets/config';

const resolveIconName = createAssetResolver<IconName>();

export { resolveIconName };

Check warning on line 17 in src/components/Assets/Icons/system/Icon.tsx

View workflow job for this annotation

GitHub Actions / code-quality-checks

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components

export interface IconProps extends SVGAttributes<SVGElement> {
name: IconName | DeprecatedIconName;
theme?: 'light' | 'dark';
name: IconName | AssetAlias | AssetDeprecatedName;
theme?: ThemeName;
size?: IconSize;
}

const Icon = ({ name, theme, size, ...props }: IconProps) => {
const { name: themeName } = useTheme();
const resolvedName = resolveIconName(name);
const resolvedTheme: ThemeName = theme ?? (themeName as ThemeName) ?? 'light';
const resolvedTheme: ThemeName = theme ?? (themeName as ThemeName) ?? THEMES.Light;
const Component =
resolvedTheme === 'light' ? IconsLight[resolvedName] : IconsDark[resolvedName];
resolvedTheme === THEMES.Light ? IconsLight[resolvedName] : IconsDark[resolvedName];

if (!Component) {
return null;
Expand Down
7 changes: 5 additions & 2 deletions src/components/Assets/Icons/system/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export { Icon, type IconProps } from './Icon';
export {
Icon,
type IconProps,
resolveIconName,
} from './Icon';
export { default as IconsLight } from './IconsLight';
export { default as IconsDark } from './IconsDark';
export type { IconName } from './types';
export type { SVGAssetProps } from '../../types';
export { resolveIconName, type DeprecatedIconName } from './retroactiveNames';
Loading
Loading