Skip to content

Commit b07f7d9

Browse files
committed
fix design review issues and fix color selector
1 parent 30d57ba commit b07f7d9

File tree

11 files changed

+121
-61
lines changed

11 files changed

+121
-61
lines changed

public/locales/en/themes.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"theme_name_light": "Light",
2323
"theme_name_dark": "Dark",
2424
"title_advance-settings-table_title-variable": "Variable",
25+
"title_advance-settings-table_title-color": "Color",
2526
"title_advance-settings-table_title-light": "Light theme value",
2627
"title_advance-settings-table_title-dark": "Dark theme value",
2728
"title_advance-color-settings-group-base": "Base",

public/locales/ru/themes.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"theme_name_light": "Светлая",
2323
"theme_name_dark": "Тёмная",
2424
"title_advance-settings-table_title-variable": "Переменная",
25+
"title_advance-settings-table_title-color": "Цвет",
2526
"title_advance-settings-table_title-light": "Значение светлой темы",
2627
"title_advance-settings-table_title-dark": "Значение тёмной темы",
2728
"title_advance-color-settings-base": "Базовый",

src/components/Themes/hooks/useThemeSemanticColorOption.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const getIconByGroup = (group: Exclude<AdvancedColorType, 'basic-palette'>) => {
5757
return <Icon data={MagicWand} />;
5858
case 'misc':
5959
return <Icon data={Cube} />;
60+
default:
61+
return <Icon data={Cube} />;
6062
}
6163
};
6264

@@ -162,5 +164,5 @@ export const useThemeSemanticColorOption = (
162164
),
163165
};
164166
});
165-
}, [themeState, themeVariant]);
167+
}, [gravityTheme, themeVariant, updatedColorToken, t]);
166168
};

src/components/Themes/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export const DEFAULT_ADVANCED_COLORS: AdvanceColors = {
257257
'brand-summary': {
258258
'brand-palette': [
259259
getDefaultAdvancedColorValue('base-background'),
260+
getDefaultAdvancedColorValue('text-brand-contrast'),
260261
{
261262
colorName: 'brand',
262263
...DEFAULT_GRAVITY_THEME.baseColors.brand,

src/components/Themes/lib/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@ export const getColorName = (colorToken: string) => {
2424
return capitalize(colorToken);
2525
}
2626

27+
if (colorToken === 'brand') {
28+
return 'Brand Color';
29+
}
30+
2731
return colorToken;
2832
};

src/components/Themes/ui/AdvancedSettingsTable/AdvancedSettingsTable.scss

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
@use '../../../../variables.scss';
2+
@use '~@gravity-ui/page-constructor/styles/variables.scss' as pcVariables;
23

34
$block: '.#{variables.$ns}advanced-color-settings-table';
45

56
#{$block} {
67
border-collapse: collapse;
78

89
&__cell {
10+
width: 410px;
911
padding-inline: var(--g-spacing-5);
1012
text-align: left;
11-
border-block-end: 1px solid var(--g-color-line-generic);
12-
border-inline-end: 1px solid var(--g-color-line-generic);
13+
border-block-end: 1px solid var(--g-color-line-generic-solid);
14+
border-inline-end: 1px solid var(--g-color-line-generic-solid);
15+
16+
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'lg')) {
17+
width: 335px;
18+
}
1319

1420
&_group {
1521
padding-block: var(--g-spacing-4) var(--g-spacing-1);
@@ -24,4 +30,9 @@ $block: '.#{variables.$ns}advanced-color-settings-table';
2430
&__row > &__cell:first-child {
2531
padding-inline-start: 0;
2632
}
33+
34+
&__theme-toggle {
35+
width: 100%;
36+
--g-border-radius-xl: 8px;
37+
}
2738
}

src/components/Themes/ui/AdvancedSettingsTable/AdvancedSettingsTable.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Text} from '@gravity-ui/uikit';
12
import {useTranslation} from 'next-i18next';
23
import {Fragment} from 'react';
34

@@ -18,7 +19,7 @@ export interface AdvancedSettingsTableProps {
1819
export const AdvancedSettingsTable = ({colorType}: AdvancedSettingsTableProps) => {
1920
const {t} = useTranslation('themes');
2021
const extraColors = useExtraColors();
21-
const columns = useColumns();
22+
const columns = useColumns({colorType});
2223

2324
return (
2425
<table className={b()}>
@@ -41,9 +42,13 @@ export const AdvancedSettingsTable = ({colorType}: AdvancedSettingsTableProps) =
4142
className={b('cell', {group: true})}
4243
key={`${group}-${key}`}
4344
>
44-
{key === 'variable'
45-
? t(`title_advance-color-settings-group-${group}`)
46-
: ''}
45+
{key === 'variable' ? (
46+
<Text variant="subheader-1">
47+
{t(`title_advance-color-settings-group-${group}`)}
48+
</Text>
49+
) : (
50+
''
51+
)}
4752
</td>
4853
))}
4954
</tr>

src/components/Themes/ui/AdvancedSettingsTable/columns.tsx

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {Flex, HelpMark, Text} from '@gravity-ui/uikit';
1+
import {Moon, Sun} from '@gravity-ui/icons';
2+
import {Flex, HelpMark, Icon, SegmentedRadioGroup, Text} from '@gravity-ui/uikit';
23
import {
34
type Theme,
45
type UtilityColor,
@@ -8,6 +9,7 @@ import {
89
} from '@gravity-ui/uikit-themer';
910
import {useTranslation} from 'next-i18next';
1011

12+
import {block} from '../../../../utils';
1113
import {useThemePaletteColor, useThemePrivateColorOptions, useThemeUtilityColor} from '../../hooks';
1214
import {useThemeSemanticColorOption} from '../../hooks/useThemeSemanticColorOption';
1315
import {getColorName, getColorPrefix} from '../../lib/utils';
@@ -18,6 +20,8 @@ import {ExtraColorName} from './ExtraColorName/ExtraColorName';
1820

1921
type ColumnProps = {colorName: string; theme: Theme; value?: string};
2022

23+
const b = block('advanced-color-settings-table');
24+
2125
const PaletteThemeValueColumn = ({colorName, theme, value}: ColumnProps) => {
2226
const [color, setColor] = useThemePaletteColor({
2327
token: colorName,
@@ -34,6 +38,11 @@ const PaletteThemeValueColumn = ({colorName, theme, value}: ColumnProps) => {
3438
);
3539
};
3640

41+
const utilityColorsForDefaultColorPicker: UtilityColor[] = [
42+
'base-background',
43+
'text-brand-contrast',
44+
];
45+
3746
const UtilityThemeValueColumn = ({
3847
colorName,
3948
theme,
@@ -50,7 +59,7 @@ const UtilityThemeValueColumn = ({
5059
createInternalUtilityColorReference(colorName),
5160
);
5261

53-
if (colorName === 'base-background') {
62+
if (utilityColorsForDefaultColorPicker.includes(colorName)) {
5463
return (
5564
<ColorPickerInput
5665
value={color}
@@ -73,7 +82,7 @@ const UtilityThemeValueColumn = ({
7382
);
7483
};
7584

76-
export const ThemeValueColumn = ({colorName, theme, value}: ColumnProps) => {
85+
const ThemeValueColumn = ({colorName, theme, value}: ColumnProps) => {
7786
const isUtilityColor = isUtilityColorToken(colorName);
7887

7988
if (isUtilityColor) {
@@ -83,10 +92,40 @@ export const ThemeValueColumn = ({colorName, theme, value}: ColumnProps) => {
8392
return <PaletteThemeValueColumn colorName={colorName} theme={theme} value={value} />;
8493
};
8594

86-
export const TitleColumn = ({value}: {value: string}) => {
95+
const TitleColumn = ({value}: {value: string}) => {
8796
return <Text variant="header-1">{value}</Text>;
8897
};
8998

99+
const ThemeToggleTitleColumn = ({
100+
theme,
101+
toggleTheme,
102+
}: {
103+
theme: Theme;
104+
toggleTheme: (theme: Theme) => void;
105+
}) => {
106+
const {t} = useTranslation('themes');
107+
108+
return (
109+
<SegmentedRadioGroup
110+
size="xl"
111+
defaultValue={theme}
112+
className={b('theme-toggle')}
113+
onChange={(e) => {
114+
toggleTheme(e.target.value as Theme);
115+
}}
116+
>
117+
<SegmentedRadioGroup.Option value="light">
118+
<Icon data={Sun} />
119+
{t('theme_name_light')}
120+
</SegmentedRadioGroup.Option>
121+
<SegmentedRadioGroup.Option value="dark">
122+
<Icon data={Moon} />
123+
{t('theme_name_dark')}
124+
</SegmentedRadioGroup.Option>
125+
</SegmentedRadioGroup>
126+
);
127+
};
128+
90129
const UtilityVariableDescription = ({name}: {name: UtilityColor}) => {
91130
const {t} = useTranslation('themes');
92131
const content = t(`text_utility-color_${name}_description`);
@@ -103,7 +142,7 @@ const UtilityVariableDescription = ({name}: {name: UtilityColor}) => {
103142
);
104143
};
105144

106-
export const VariableColumn = ({name, extraVariable}: {name: string; extraVariable?: boolean}) => {
145+
const VariableColumn = ({name, extraVariable}: {name: string; extraVariable?: boolean}) => {
107146
if (extraVariable) {
108147
return <ExtraColorName token={name} />;
109148
}
@@ -126,3 +165,5 @@ export const VariableColumn = ({name, extraVariable}: {name: string; extraVariab
126165
</Flex>
127166
);
128167
};
168+
169+
export {ThemeValueColumn, TitleColumn, VariableColumn, ThemeToggleTitleColumn};
Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import {Moon, Sun} from '@gravity-ui/icons';
21
import {BREAKPOINTS, useWindowBreakpoint} from '@gravity-ui/page-constructor';
3-
import {Icon, SegmentedRadioGroup} from '@gravity-ui/uikit';
42
import type {BaseColors, Theme} from '@gravity-ui/uikit-themer';
53
import {useTranslation} from 'next-i18next';
64
import {type ReactElement, useMemo, useState} from 'react';
75

86
import {useThemeCreator} from '../../hooks';
97
import {isManuallyCreatedPaletteToken} from '../../lib/themeCreatorUtils';
8+
import type {AdvancedColorType} from '../../lib/types';
109

11-
import {ThemeValueColumn, TitleColumn, VariableColumn} from './columns';
10+
import {ThemeToggleTitleColumn, ThemeValueColumn, TitleColumn, VariableColumn} from './columns';
1211

1312
export const useExtraColors = () => {
1413
const {gravityTheme} = useThemeCreator();
@@ -34,7 +33,7 @@ type Column = {
3433
}) => ReactElement;
3534
};
3635

37-
export const useColumns = (): Column[] => {
36+
export const useColumns = ({colorType}: {colorType: AdvancedColorType}): Column[] => {
3837
const [theme, toggleTheme] = useState<Theme>('light');
3938
const {t} = useTranslation('themes');
4039

@@ -43,7 +42,15 @@ export const useColumns = (): Column[] => {
4342

4443
const variableColumn: Column = useMemo(
4544
() => ({
46-
title: () => <TitleColumn value={t('title_advance-settings-table_title-variable')} />,
45+
title: () => (
46+
<TitleColumn
47+
value={
48+
colorType === 'basic-palette'
49+
? t('title_advance-settings-table_title-color')
50+
: t('title_advance-settings-table_title-variable')
51+
}
52+
/>
53+
),
4754
key: 'variable',
4855
render: ({colorName, extraVariable = false}) => (
4956
<VariableColumn name={colorName} extraVariable={extraVariable} />
@@ -52,44 +59,25 @@ export const useColumns = (): Column[] => {
5259
[t],
5360
);
5461

55-
if (isTablet) {
56-
return useMemo(
57-
() => [
58-
variableColumn,
59-
{
60-
title: () => (
61-
<SegmentedRadioGroup
62-
size="xl"
63-
defaultValue={theme}
64-
onChange={(e) => {
65-
toggleTheme(e.target.value as Theme);
66-
}}
67-
>
68-
<SegmentedRadioGroup.Option value="light">
69-
<Icon data={Sun} />
70-
{t('theme_name_light')}
71-
</SegmentedRadioGroup.Option>
72-
<SegmentedRadioGroup.Option value="dark">
73-
<Icon data={Moon} />
74-
{t('theme_name_dark')}
75-
</SegmentedRadioGroup.Option>
76-
</SegmentedRadioGroup>
77-
),
78-
key: 'themeToggle',
79-
render: ({colorName, light, dark}) => (
80-
<ThemeValueColumn
81-
theme={theme}
82-
colorName={colorName}
83-
value={theme === 'light' ? light : dark}
84-
/>
85-
),
86-
},
87-
],
88-
[theme, t],
89-
);
90-
}
62+
const tabletColumns: Column[] = useMemo(
63+
() => [
64+
variableColumn,
65+
{
66+
title: () => <ThemeToggleTitleColumn theme={theme} toggleTheme={toggleTheme} />,
67+
key: 'themeToggle',
68+
render: ({colorName, light, dark}) => (
69+
<ThemeValueColumn
70+
theme={theme}
71+
colorName={colorName}
72+
value={theme === 'light' ? light : dark}
73+
/>
74+
),
75+
},
76+
],
77+
[variableColumn, theme],
78+
);
9179

92-
return useMemo(
80+
const desktopColumns: Column[] = useMemo(
9381
() => [
9482
variableColumn,
9583
{
@@ -107,6 +95,12 @@ export const useColumns = (): Column[] => {
10795
),
10896
},
10997
],
110-
[t],
98+
[variableColumn, t],
11199
);
100+
101+
if (isTablet) {
102+
return tabletColumns;
103+
}
104+
105+
return desktopColumns;
112106
};

src/components/Themes/ui/GravityColorSelect/ColorSelectPopupContent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export const ColorSelectPopupContent = ({
9090
<PrivateColorsList
9191
colors={privateGroups}
9292
value={groupToken}
93-
onSelect={(val) => {
94-
setCurrentGroupToken(val);
93+
onSelect={(item) => {
94+
setCurrentGroupToken(item.token);
9595
setSelectedGroupType('private');
9696
}}
9797
view={version === 'mobile' ? 'select' : 'list'}
@@ -128,7 +128,7 @@ export const ColorSelectPopupContent = ({
128128
<PrivateColorsList
129129
colors={groupPrivateColors}
130130
value={value}
131-
onSelect={onChange}
131+
onSelect={(item) => onChange(item.color, item.token)}
132132
/>
133133
)}
134134
</div>

0 commit comments

Comments
 (0)