-
-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert manage theme followup #2889
Changes from 11 commits
d783aa7
3ac8903
52aba63
1f3cf5e
15eee23
a057e70
ec2130a
a692010
e3fc17a
bba60a3
ea45c94
6991b4f
494af38
ae73ceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { | |
Box, Button, IconButton, Stack, | ||
} from '@tokens-studio/ui'; | ||
import { NavArrowLeft } from 'iconoir-react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { allTokenSetsSelector, themesListSelector, usedTokenSetSelector } from '@/selectors'; | ||
import { StyledNameInputBox } from './StyledNameInputBox'; | ||
import { StyledCreateOrEditThemeFormHeaderFlex } from './StyledCreateOrEditThemeFormHeaderFlex'; | ||
|
@@ -53,20 +54,29 @@ export const CreateOrEditThemeForm: React.FC<React.PropsWithChildren<React.Props | |
const availableTokenSets = useSelector(allTokenSetsSelector); | ||
const themes = useSelector(themesListSelector); | ||
const groupNames = useMemo(() => ([...new Set(themes.filter((t) => t?.group).map((t) => t.group as string))]), [themes]); | ||
const { t } = useTranslation(['tokens', 'errors']); | ||
|
||
const treeOrListItems = useMemo(() => ( | ||
githubMfsEnabled | ||
? tokenSetListToTree(availableTokenSets) | ||
: tokenSetListToList(availableTokenSets) | ||
), [githubMfsEnabled, availableTokenSets]); | ||
|
||
const { register, handleSubmit, control } = useForm<FormValues>({ | ||
const { register, handleSubmit, control, resetField } = useForm<FormValues>({ | ||
defaultValues: { | ||
tokenSets: { ...selectedTokenSets }, | ||
...defaultValues, | ||
}, | ||
}); | ||
|
||
const handleKeyDown = useCallback((fieldName: keyof FormValues) => (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Escape') { | ||
e.stopPropagation(); | ||
resetField(fieldName); | ||
setShowGroupInput(false); | ||
} | ||
}, [handleSubmit]); | ||
|
||
const TokenSetThemeItemInput = useCallback((props: React.PropsWithChildren<{ item: TreeItem }>) => ( | ||
<Controller | ||
name="tokenSets" | ||
|
@@ -92,7 +102,7 @@ export const CreateOrEditThemeForm: React.FC<React.PropsWithChildren<React.Props | |
<StyledNameInputBox css={{ width: '100%' }}> | ||
<StyledCreateOrEditThemeFormHeaderFlex> | ||
<IconButton | ||
tooltip="Return to overview" | ||
tooltip={t('returnToOverview')} | ||
data-testid="button-return-to-overview" | ||
icon={<NavArrowLeft />} | ||
size="small" | ||
|
@@ -117,7 +127,8 @@ export const CreateOrEditThemeForm: React.FC<React.PropsWithChildren<React.Props | |
autofocus | ||
data-testid="create-or-edit-theme-form--group--name" | ||
{...register('group')} | ||
placeholder="Add group" | ||
placeholder={t('addGroup')} | ||
onKeyDown={handleKeyDown('group')} | ||
css={{ | ||
display: 'flex', | ||
}} | ||
|
@@ -146,9 +157,8 @@ export const CreateOrEditThemeForm: React.FC<React.PropsWithChildren<React.Props | |
icon={<IconPlus />} | ||
onClick={handleAddGroup} | ||
size="small" | ||
css={{ display: 'flex', alignItems: 'center', height: '28px' }} | ||
> | ||
Add group | ||
{t('addGroup')} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree should also be solveable with css |
||
</Button> | ||
) | ||
} | ||
|
@@ -162,7 +172,7 @@ export const CreateOrEditThemeForm: React.FC<React.PropsWithChildren<React.Props | |
full | ||
data-testid="create-or-edit-theme-form--input--name" | ||
{...register('name', { required: true })} | ||
placeholder="Theme name" | ||
placeholder={t('themeName')} | ||
/> | ||
</Stack> | ||
</Stack> | ||
|
@@ -172,8 +182,8 @@ export const CreateOrEditThemeForm: React.FC<React.PropsWithChildren<React.Props | |
{id && ( | ||
|
||
<StyledCreateOrEditThemeFormTabsFlex> | ||
<TabButton name={ThemeFormTabs.SETS} activeTab={activeTab} label="Sets" onSwitch={setActiveTab} small /> | ||
<TabButton name={ThemeFormTabs.STYLES_VARIABLES} activeTab={activeTab} label="Styles & Variables" onSwitch={setActiveTab} small /> | ||
<TabButton name={ThemeFormTabs.SETS} activeTab={activeTab} label={t('sets.title')} onSwitch={setActiveTab} small /> | ||
<TabButton name={ThemeFormTabs.STYLES_VARIABLES} activeTab={activeTab} label={t('stylesAndVariables')} onSwitch={setActiveTab} small /> | ||
</StyledCreateOrEditThemeFormTabsFlex> | ||
)} | ||
<Stack direction="column" gap={1}> | ||
|
@@ -188,7 +198,9 @@ export const CreateOrEditThemeForm: React.FC<React.PropsWithChildren<React.Props | |
)} | ||
{(activeTab === ThemeFormTabs.STYLES_VARIABLES && id) && ( | ||
<Box css={{ padding: '$3' }}> | ||
<Box css={{ padding: '$1', marginBottom: '$2' }}>Note: When using multi-dimensional themes where values depend on tokens of another theme, connecting styles might not work as expected.</Box> | ||
<Box css={{ padding: '$1', marginBottom: '$2' }}> | ||
{t('stylesVarMultiDimensionalThemesWarning')} | ||
</Box> | ||
<ThemeStyleManagementForm id={id} /> | ||
</Box> | ||
)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this not be calling it all the time on any key down event? 🧐
would that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the function
handleKeyDown
tohandleGroupKeyDown
, the'group'
argument here is redundant since the function is only being used in one place.