feat: add Settings/Accounts Connected Accounts section accounts list (#2953)

Closes #2887
This commit is contained in:
Thaïs
2023-12-12 16:03:39 +01:00
committed by GitHub
parent 2a4ab2ffd3
commit 0048216abf
24 changed files with 437 additions and 201 deletions

View File

@ -0,0 +1 @@
export type Account = { email: string; uuid: string };

View File

@ -28,7 +28,7 @@ export const AddObjectFilterFromDetailsButton = ({
return ( return (
<LightButton <LightButton
onClick={handleClick} onClick={handleClick}
icon={<IconPlus />} Icon={IconPlus}
title="Add filter" title="Add filter"
accent="tertiary" accent="tertiary"
/> />

View File

@ -0,0 +1,60 @@
import { useNavigate } from 'react-router-dom';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Account } from '@/accounts/types/Account';
import { IconAt, IconPlus } from '@/ui/display/icon';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Card } from '@/ui/layout/card/components/Card';
import { CardFooter } from '@/ui/layout/card/components/CardFooter';
import { SettingsAccountRow } from './SettingsAccountsRow';
const StyledFooter = styled(CardFooter)`
align-items: center;
color: ${({ theme }) => theme.font.color.tertiary};
display: flex;
gap: ${({ theme }) => theme.spacing(2)};
height: ${({ theme }) => theme.spacing(6)};
padding: ${({ theme }) => theme.spacing(2)};
padding-left: ${({ theme }) => theme.spacing(4)};
`;
const StyledIconButton = styled(LightIconButton)`
margin-left: auto;
`;
type SettingsAccountsCardProps = {
accounts: Account[];
onAccountRemove?: (uuid: string) => void;
};
export const SettingsAccountsCard = ({
accounts,
onAccountRemove,
}: SettingsAccountsCardProps) => {
const theme = useTheme();
const navigate = useNavigate();
return (
<Card>
{accounts.map((account, index) => (
<SettingsAccountRow
key={account.uuid}
account={account}
divider={index < accounts.length - 1}
onRemove={onAccountRemove}
/>
))}
<StyledFooter>
<IconAt size={theme.icon.size.sm} />
Add account
<StyledIconButton
Icon={IconPlus}
accent="tertiary"
onClick={() => navigate('/settings/accounts/new')}
/>
</StyledFooter>
</Card>
);
};

View File

@ -1,14 +1,34 @@
import { useState } from 'react';
import { H2Title } from '@/ui/display/typography/components/H2Title'; import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Section } from '@/ui/layout/section/components/Section'; import { Section } from '@/ui/layout/section/components/Section';
import { mockedAccounts } from '~/testing/mock-data/accounts';
import { SettingsAccountsCard } from './SettingsAccountsCard';
import { SettingsAccountsEmptyStateCard } from './SettingsAccountsEmptyStateCard'; import { SettingsAccountsEmptyStateCard } from './SettingsAccountsEmptyStateCard';
export const SettingsAccountsConnectedAccountsSection = () => ( export const SettingsAccountsConnectedAccountsSection = () => {
<Section> const [accounts, setAccounts] = useState(mockedAccounts);
<H2Title
title="Connected accounts" const handleAccountRemove = (uuid: string) =>
description="Manage your internet accounts." setAccounts((previousAccounts) =>
/> previousAccounts.filter((account) => account.uuid !== uuid),
<SettingsAccountsEmptyStateCard /> );
</Section>
); return (
<Section>
<H2Title
title="Connected accounts"
description="Manage your internet accounts."
/>
{accounts.length ? (
<SettingsAccountsCard
accounts={accounts}
onAccountRemove={handleAccountRemove}
/>
) : (
<SettingsAccountsEmptyStateCard />
)}
</Section>
);
};

View File

@ -4,30 +4,20 @@ import styled from '@emotion/styled';
import { IconGoogle } from '@/ui/display/icon/components/IconGoogle'; import { IconGoogle } from '@/ui/display/icon/components/IconGoogle';
import { Button } from '@/ui/input/button/components/Button'; import { Button } from '@/ui/input/button/components/Button';
import { Card } from '@/ui/layout/card/components/Card'; import { Card } from '@/ui/layout/card/components/Card';
import { CardContent } from '@/ui/layout/card/components/CardContent';
import { CardHeader } from '@/ui/layout/card/components/CardHeader';
import { REACT_APP_SERVER_AUTH_URL } from '~/config'; import { REACT_APP_SERVER_AUTH_URL } from '~/config';
import { useGenerateTransientTokenMutation } from '~/generated/graphql'; import { useGenerateTransientTokenMutation } from '~/generated/graphql';
const StyledCard = styled(Card)` const StyledHeader = styled(CardHeader)`
border-radius: ${({ theme }) => theme.border.radius.md};
overflow: hidden;
padding: 0;
`;
const StyledHeader = styled.div`
align-items: center; align-items: center;
background-color: ${({ theme }) => theme.background.primary};
border-bottom: 1px solid ${({ theme }) => theme.border.color.light};
display: flex; display: flex;
font-size: ${({ theme }) => theme.font.size.sm};
font-weight: ${({ theme }) => theme.font.weight.medium};
height: ${({ theme }) => theme.spacing(6)}; height: ${({ theme }) => theme.spacing(6)};
padding: ${({ theme }) => theme.spacing(2, 4)};
`; `;
const StyledBody = styled.div` const StyledBody = styled(CardContent)`
display: flex; display: flex;
justify-content: center; justify-content: center;
padding: ${({ theme }) => theme.spacing(4)};
`; `;
export const SettingsAccountsEmptyStateCard = () => { export const SettingsAccountsEmptyStateCard = () => {
@ -43,8 +33,9 @@ export const SettingsAccountsEmptyStateCard = () => {
window.location.href = `${authServerUrl}/google-gmail?transientToken=${token}`; window.location.href = `${authServerUrl}/google-gmail?transientToken=${token}`;
}, [generateTransientToken]); }, [generateTransientToken]);
return ( return (
<StyledCard> <Card>
<StyledHeader>No connected account</StyledHeader> <StyledHeader>No connected account</StyledHeader>
<StyledBody> <StyledBody>
<Button <Button
@ -54,6 +45,6 @@ export const SettingsAccountsEmptyStateCard = () => {
onClick={handleGmailLogin} onClick={handleGmailLogin}
/> />
</StyledBody> </StyledBody>
</StyledCard> </Card>
); );
}; };

View File

@ -0,0 +1,88 @@
import { useNavigate } from 'react-router-dom';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Account } from '@/accounts/types/Account';
import { IconDotsVertical, IconMail, IconTrash } from '@/ui/display/icon';
import { IconGoogle } from '@/ui/display/icon/components/IconGoogle';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { CardContent } from '@/ui/layout/card/components/CardContent';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
import { DropdownScope } from '@/ui/layout/dropdown/scopes/DropdownScope';
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
const StyledRow = styled(CardContent)`
align-items: center;
display: flex;
font-size: ${({ theme }) => theme.font.size.sm};
font-weight: ${({ theme }) => theme.font.weight.medium};
gap: ${({ theme }) => theme.spacing(2)};
padding: ${({ theme }) => theme.spacing(2)};
padding-left: ${({ theme }) => theme.spacing(4)};
`;
const StyledDropdown = styled(Dropdown)`
margin-left: auto;
`;
type SettingsAccountRowProps = {
account: Account;
divider?: boolean;
onRemove?: (uuid: string) => void;
};
export const SettingsAccountRow = ({
account,
divider,
onRemove,
}: SettingsAccountRowProps) => {
const dropdownScopeId = `settings-account-row-${account.uuid}`;
const theme = useTheme();
const navigate = useNavigate();
const { closeDropdown } = useDropdown({ dropdownScopeId });
return (
<StyledRow divider={divider}>
<IconGoogle size={theme.icon.size.sm} />
{account.email}
<DropdownScope dropdownScopeId={dropdownScopeId}>
<StyledDropdown
dropdownPlacement="right-start"
dropdownHotkeyScope={{ scope: dropdownScopeId }}
clickableComponent={
<LightIconButton Icon={IconDotsVertical} accent="tertiary" />
}
dropdownComponents={
<DropdownMenu>
<DropdownMenuItemsContainer>
<MenuItem
LeftIcon={IconMail}
text="Emails settings"
onClick={() => {
navigate(`/settings/accounts/emails/${account.uuid}`);
closeDropdown();
}}
/>
{!!onRemove && (
<MenuItem
accent="danger"
LeftIcon={IconTrash}
text="Remove account"
onClick={() => {
onRemove(account.uuid);
closeDropdown();
}}
/>
)}
</DropdownMenuItemsContainer>
</DropdownMenu>
}
/>
</DropdownScope>
</StyledRow>
);
};

View File

@ -6,6 +6,7 @@ import { IconChevronRight } from '@/ui/display/icon';
import { IconComponent } from '@/ui/display/icon/types/IconComponent'; import { IconComponent } from '@/ui/display/icon/types/IconComponent';
import { SoonPill } from '@/ui/display/pill/components/SoonPill'; import { SoonPill } from '@/ui/display/pill/components/SoonPill';
import { Card } from '@/ui/layout/card/components/Card'; import { Card } from '@/ui/layout/card/components/Card';
import { CardContent } from '@/ui/layout/card/components/CardContent';
type SettingsNavigationCardProps = { type SettingsNavigationCardProps = {
children: ReactNode; children: ReactNode;
@ -23,11 +24,13 @@ const StyledCard = styled(Card)<{
color: ${({ theme }) => theme.font.color.tertiary}; color: ${({ theme }) => theme.font.color.tertiary};
cursor: ${({ disabled, onClick }) => cursor: ${({ disabled, onClick }) =>
disabled ? 'not-allowed' : onClick ? 'pointer' : 'default'}; disabled ? 'not-allowed' : onClick ? 'pointer' : 'default'};
`;
const StyledCardContent = styled(CardContent)`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: ${({ theme }) => theme.spacing(2)}; gap: ${({ theme }) => theme.spacing(2)};
padding-bottom: ${({ theme }) => theme.spacing(4)}; padding: ${({ theme }) => theme.spacing(4, 3)};
padding-top: ${({ theme }) => theme.spacing(4)};
`; `;
const StyledHeader = styled.div` const StyledHeader = styled.div`
@ -65,15 +68,17 @@ export const SettingsNavigationCard = ({
return ( return (
<StyledCard disabled={disabled} onClick={onClick}> <StyledCard disabled={disabled} onClick={onClick}>
<StyledHeader> <StyledCardContent>
<Icon size={theme.icon.size.lg} stroke={theme.icon.stroke.sm} /> <StyledHeader>
<StyledTitle> <Icon size={theme.icon.size.lg} stroke={theme.icon.stroke.sm} />
{title} <StyledTitle>
{hasSoonPill && <SoonPill />} {title}
</StyledTitle> {hasSoonPill && <SoonPill />}
<StyledIconChevronRight size={theme.icon.size.sm} /> </StyledTitle>
</StyledHeader> <StyledIconChevronRight size={theme.icon.size.sm} />
<StyledDescription>{children}</StyledDescription> </StyledHeader>
<StyledDescription>{children}</StyledDescription>
</StyledCardContent>
</StyledCard> </StyledCard>
); );
}; };

View File

@ -7,6 +7,8 @@ import { FieldContext } from '@/object-record/field/contexts/FieldContext';
import { BooleanFieldInput } from '@/object-record/field/meta-types/input/components/BooleanFieldInput'; import { BooleanFieldInput } from '@/object-record/field/meta-types/input/components/BooleanFieldInput';
import { RatingFieldInput } from '@/object-record/field/meta-types/input/components/RatingFieldInput'; import { RatingFieldInput } from '@/object-record/field/meta-types/input/components/RatingFieldInput';
import { Tag } from '@/ui/display/tag/components/Tag'; import { Tag } from '@/ui/display/tag/components/Tag';
import { Card } from '@/ui/layout/card/components/Card';
import { CardContent } from '@/ui/layout/card/components/CardContent';
import { Field, FieldMetadataType } from '~/generated-metadata/graphql'; import { Field, FieldMetadataType } from '~/generated-metadata/graphql';
import { SettingsObjectFieldPreviewValueEffect } from '../components/SettingsObjectFieldPreviewValueEffect'; import { SettingsObjectFieldPreviewValueEffect } from '../components/SettingsObjectFieldPreviewValueEffect';
@ -23,13 +25,14 @@ export type SettingsObjectFieldPreviewProps = {
shrink?: boolean; shrink?: boolean;
}; };
const StyledContainer = styled.div` const StyledCard = styled(Card)`
background-color: ${({ theme }) => theme.background.secondary};
border: 1px solid ${({ theme }) => theme.border.color.medium};
border-radius: ${({ theme }) => theme.border.radius.md}; border-radius: ${({ theme }) => theme.border.radius.md};
box-sizing: border-box;
color: ${({ theme }) => theme.font.color.primary}; color: ${({ theme }) => theme.font.color.primary};
max-width: 480px; max-width: 480px;
`;
const StyledCardContent = styled(CardContent)`
display: grid;
padding: ${({ theme }) => theme.spacing(2)}; padding: ${({ theme }) => theme.spacing(2)};
`; `;
@ -95,65 +98,67 @@ export const SettingsObjectFieldPreview = ({
}); });
return ( return (
<StyledContainer className={className}> <StyledCard className={className}>
<StyledObjectSummary> <StyledCardContent>
<StyledObjectName> <StyledObjectSummary>
{!!ObjectIcon && ( <StyledObjectName>
<ObjectIcon {!!ObjectIcon && (
size={theme.icon.size.sm} <ObjectIcon
stroke={theme.icon.stroke.sm} size={theme.icon.size.sm}
/> stroke={theme.icon.stroke.sm}
)} />
{objectMetadataItem?.labelPlural} )}
</StyledObjectName> {objectMetadataItem?.labelPlural}
{objectMetadataItem?.isCustom ? ( </StyledObjectName>
<Tag color="orange" text="Custom" /> {objectMetadataItem?.isCustom ? (
) : ( <Tag color="orange" text="Custom" />
<Tag color="blue" text="Standard" />
)}
</StyledObjectSummary>
<SettingsObjectFieldPreviewValueEffect
entityId={entityId}
fieldName={fieldName}
value={value}
/>
<StyledFieldPreview shrink={shrink}>
<StyledFieldLabel>
{!!FieldIcon && (
<FieldIcon
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
/>
)}
{fieldMetadata.label}:
</StyledFieldLabel>
<FieldContext.Provider
value={{
entityId,
isLabelIdentifier: false,
fieldDefinition: {
type: parseFieldType(fieldMetadata.type),
iconName: 'FieldIcon',
fieldMetadataId: fieldMetadata.id || '',
label: fieldMetadata.label,
metadata: {
fieldName,
relationObjectMetadataNameSingular:
relationObjectMetadataItem?.nameSingular,
},
},
hotkeyScope: 'field-preview',
}}
>
{fieldMetadata.type === FieldMetadataType.Boolean ? (
<BooleanFieldInput readonly />
) : fieldMetadata.type === FieldMetadataType.Rating ? (
<RatingFieldInput readonly />
) : ( ) : (
<FieldDisplay /> <Tag color="blue" text="Standard" />
)} )}
</FieldContext.Provider> </StyledObjectSummary>
</StyledFieldPreview> <SettingsObjectFieldPreviewValueEffect
</StyledContainer> entityId={entityId}
fieldName={fieldName}
value={value}
/>
<StyledFieldPreview shrink={shrink}>
<StyledFieldLabel>
{!!FieldIcon && (
<FieldIcon
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
/>
)}
{fieldMetadata.label}:
</StyledFieldLabel>
<FieldContext.Provider
value={{
entityId,
isLabelIdentifier: false,
fieldDefinition: {
type: parseFieldType(fieldMetadata.type),
iconName: 'FieldIcon',
fieldMetadataId: fieldMetadata.id || '',
label: fieldMetadata.label,
metadata: {
fieldName,
relationObjectMetadataNameSingular:
relationObjectMetadataItem?.nameSingular,
},
},
hotkeyScope: 'field-preview',
}}
>
{fieldMetadata.type === FieldMetadataType.Boolean ? (
<BooleanFieldInput readonly />
) : fieldMetadata.type === FieldMetadataType.Rating ? (
<RatingFieldInput readonly />
) : (
<FieldDisplay />
)}
</FieldContext.Provider>
</StyledFieldPreview>
</StyledCardContent>
</StyledCard>
); );
}; };

View File

@ -71,6 +71,7 @@ export const SettingsObjectFieldRelationForm = ({
<Select <Select
label="Relation type" label="Relation type"
dropdownScopeId="relation-type-select" dropdownScopeId="relation-type-select"
fullWidth
disabled={disableRelationEdition} disabled={disableRelationEdition}
value={values.type} value={values.type}
options={Object.entries(relationTypes).map( options={Object.entries(relationTypes).map(
@ -85,6 +86,7 @@ export const SettingsObjectFieldRelationForm = ({
<Select <Select
label="Object destination" label="Object destination"
dropdownScopeId="object-destination-select" dropdownScopeId="object-destination-select"
fullWidth
disabled={disableRelationEdition} disabled={disableRelationEdition}
value={values.objectMetadataId} value={values.objectMetadataId}
options={objectMetadataItems.map((objectMetadataItem) => ({ options={objectMetadataItems.map((objectMetadataItem) => ({

View File

@ -3,7 +3,9 @@ import { DropResult } from '@hello-pangea/dnd';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
import { IconPlus } from '@/ui/display/icon'; import { IconPlus } from '@/ui/display/icon';
import { Button } from '@/ui/input/button/components/Button'; import { LightButton } from '@/ui/input/button/components/LightButton';
import { CardContent } from '@/ui/layout/card/components/CardContent';
import { CardFooter } from '@/ui/layout/card/components/CardFooter';
import { DraggableItem } from '@/ui/layout/draggable-list/components/DraggableItem'; import { DraggableItem } from '@/ui/layout/draggable-list/components/DraggableItem';
import { DraggableList } from '@/ui/layout/draggable-list/components/DraggableList'; import { DraggableList } from '@/ui/layout/draggable-list/components/DraggableList';
import { mainColorNames, ThemeColor } from '@/ui/theme/constants/colors'; import { mainColorNames, ThemeColor } from '@/ui/theme/constants/colors';
@ -20,8 +22,7 @@ type SettingsObjectFieldSelectFormProps = {
values: SettingsObjectFieldSelectFormValues; values: SettingsObjectFieldSelectFormValues;
}; };
const StyledContainer = styled.div` const StyledContainer = styled(CardContent)`
padding: ${({ theme }) => theme.spacing(4)};
padding-bottom: ${({ theme }) => theme.spacing(3.5)}; padding-bottom: ${({ theme }) => theme.spacing(3.5)};
`; `;
@ -35,13 +36,14 @@ const StyledLabel = styled.span`
text-transform: uppercase; text-transform: uppercase;
`; `;
const StyledButton = styled(Button)` const StyledFooter = styled(CardFooter)`
border-bottom: 0; background-color: ${({ theme }) => theme.background.secondary};
border-left: 0; padding: ${({ theme }) => theme.spacing(1)};
border-radius: 0; `;
border-right: 0;
const StyledButton = styled(LightButton)`
justify-content: center; justify-content: center;
text-align: center; width: 100%;
`; `;
const getNextColor = (currentColor: ThemeColor) => { const getNextColor = (currentColor: ThemeColor) => {
@ -117,21 +119,22 @@ export const SettingsObjectFieldSelectForm = ({
} }
/> />
</StyledContainer> </StyledContainer>
<StyledButton <StyledFooter>
title="Add option" <StyledButton
fullWidth title="Add option"
Icon={IconPlus} Icon={IconPlus}
onClick={() => onClick={() =>
onChange([ onChange([
...values, ...values,
{ {
color: getNextColor(values[values.length - 1].color), color: getNextColor(values[values.length - 1].color),
label: `Option ${values.length + 1}`, label: `Option ${values.length + 1}`,
value: v4(), value: v4(),
}, },
]) ])
} }
/> />
</StyledFooter>
</> </>
); );
}; };

View File

@ -2,6 +2,7 @@ import { ReactNode } from 'react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { Card } from '@/ui/layout/card/components/Card'; import { Card } from '@/ui/layout/card/components/Card';
import { CardContent } from '@/ui/layout/card/components/CardContent';
type SettingsObjectFieldTypeCardProps = { type SettingsObjectFieldTypeCardProps = {
className?: string; className?: string;
@ -9,14 +10,10 @@ type SettingsObjectFieldTypeCardProps = {
form?: ReactNode; form?: ReactNode;
}; };
const StyledPreviewContainer = styled(Card)` const StyledCard = styled(Card)``;
background-color: ${({ theme }) => theme.background.transparent.lighter};
padding: ${({ theme }) => theme.spacing(4)};
&:not(:last-child) { const StyledPreviewContainer = styled(CardContent)`
border-bottom-left-radius: 0; background-color: ${({ theme }) => theme.background.transparent.lighter};
border-bottom-right-radius: 0;
}
`; `;
const StyledTitle = styled.h3` const StyledTitle = styled.h3`
@ -32,11 +29,7 @@ const StyledPreviewContent = styled.div`
gap: 6px; gap: 6px;
`; `;
const StyledFormContainer = styled(Card)` const StyledFormContainer = styled(CardContent)`
border-top: 0;
border-top-left-radius: 0;
border-top-right-radius: 0;
overflow: hidden;
padding: 0; padding: 0;
`; `;
@ -46,12 +39,12 @@ export const SettingsObjectFieldTypeCard = ({
form, form,
}: SettingsObjectFieldTypeCardProps) => { }: SettingsObjectFieldTypeCardProps) => {
return ( return (
<div className={className}> <StyledCard className={className}>
<StyledPreviewContainer> <StyledPreviewContainer divider={!!form}>
<StyledTitle>Preview</StyledTitle> <StyledTitle>Preview</StyledTitle>
<StyledPreviewContent>{preview}</StyledPreviewContent> <StyledPreviewContent>{preview}</StyledPreviewContent>
</StyledPreviewContainer> </StyledPreviewContainer>
{!!form && <StyledFormContainer>{form}</StyledFormContainer>} {!!form && <StyledFormContainer>{form}</StyledFormContainer>}
</div> </StyledCard>
); );
}; };

View File

@ -77,6 +77,7 @@ export const SettingsObjectFieldTypeSelectSection = ({
description="The field's type and values." description="The field's type and values."
/> />
<Select <Select
fullWidth
disabled={!!fieldMetadata?.id} disabled={!!fieldMetadata?.id}
dropdownScopeId="object-field-type-select" dropdownScopeId="object-field-type-select"
value={values?.type} value={values?.type}

View File

@ -7,6 +7,7 @@ import { H2Title } from '@/ui/display/typography/components/H2Title';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton'; import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { useLazyLoadIcon } from '@/ui/input/hooks/useLazyLoadIcon'; import { useLazyLoadIcon } from '@/ui/input/hooks/useLazyLoadIcon';
import { Card } from '@/ui/layout/card/components/Card'; import { Card } from '@/ui/layout/card/components/Card';
import { CardContent } from '@/ui/layout/card/components/CardContent';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown'; import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu'; import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer'; import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
@ -23,7 +24,7 @@ type SettingsAboutSectionProps = {
onEdit: () => void; onEdit: () => void;
}; };
const StyledCard = styled(Card)` const StyledCardContent = styled(CardContent)`
align-items: center; align-items: center;
display: flex; display: flex;
gap: ${({ theme }) => theme.spacing(2)}; gap: ${({ theme }) => theme.spacing(2)};
@ -69,43 +70,45 @@ export const SettingsAboutSection = ({
return ( return (
<Section> <Section>
<H2Title title="About" description="Manage your object" /> <H2Title title="About" description="Manage your object" />
<StyledCard> <Card>
<StyledName> <StyledCardContent>
{!!Icon && <Icon size={theme.icon.size.md} />} <StyledName>
{name} {!!Icon && <Icon size={theme.icon.size.md} />}
</StyledName> {name}
{isCustom ? ( </StyledName>
<StyledTag color="orange" text="Custom" /> {isCustom ? (
) : ( <StyledTag color="orange" text="Custom" />
<StyledTag color="blue" text="Standard" /> ) : (
)} <StyledTag color="blue" text="Standard" />
<DropdownScope dropdownScopeId={dropdownScopeId}> )}
<Dropdown <DropdownScope dropdownScopeId={dropdownScopeId}>
clickableComponent={ <Dropdown
<LightIconButton Icon={IconDotsVertical} accent="tertiary" /> clickableComponent={
} <LightIconButton Icon={IconDotsVertical} accent="tertiary" />
dropdownComponents={ }
<DropdownMenu width="160px"> dropdownComponents={
<DropdownMenuItemsContainer> <DropdownMenu width="160px">
<MenuItem <DropdownMenuItemsContainer>
text="Edit" <MenuItem
LeftIcon={IconPencil} text="Edit"
onClick={handleEdit} LeftIcon={IconPencil}
/> onClick={handleEdit}
<MenuItem />
text="Disable" <MenuItem
LeftIcon={IconArchive} text="Disable"
onClick={handleDisable} LeftIcon={IconArchive}
/> onClick={handleDisable}
</DropdownMenuItemsContainer> />
</DropdownMenu> </DropdownMenuItemsContainer>
} </DropdownMenu>
dropdownHotkeyScope={{ }
scope: dropdownScopeId, dropdownHotkeyScope={{
}} scope: dropdownScopeId,
/> }}
</DropdownScope> />
</StyledCard> </DropdownScope>
</StyledCardContent>
</Card>
</Section> </Section>
); );
}; };

View File

@ -4,16 +4,16 @@ import styled from '@emotion/styled';
import { IconX } from '@/ui/display/icon'; import { IconX } from '@/ui/display/icon';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton'; import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Card } from '@/ui/layout/card/components/Card';
import { AnimatedFadeOut } from '@/ui/utilities/animation/components/AnimatedFadeOut'; import { AnimatedFadeOut } from '@/ui/utilities/animation/components/AnimatedFadeOut';
import { cookieStorage } from '~/utils/cookie-storage'; import { cookieStorage } from '~/utils/cookie-storage';
import CoverImage from '../assets/cover.png'; import CoverImage from '../assets/cover.png';
const StyledCoverImageContainer = styled.div` const StyledCoverImageContainer = styled(Card)`
align-items: center; align-items: center;
background-image: url(${CoverImage.toString()}); background-image: url(${CoverImage.toString()});
background-size: cover; background-size: cover;
border: 1px solid ${({ theme }) => theme.border.color.medium};
border-radius: ${({ theme }) => theme.border.radius.md}; border-radius: ${({ theme }) => theme.border.radius.md};
box-sizing: border-box; box-sizing: border-box;
display: flex; display: flex;

View File

@ -1,13 +1,14 @@
import React, { MouseEvent, useMemo } from 'react'; import { MouseEvent } from 'react';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { TablerIconsProps } from '@/ui/display/icon'; import { IconComponent } from '@/ui/display/icon/types/IconComponent';
export type LightButtonAccent = 'secondary' | 'tertiary'; export type LightButtonAccent = 'secondary' | 'tertiary';
export type LightButtonProps = { export type LightButtonProps = {
className?: string; className?: string;
icon?: React.ReactNode; Icon?: IconComponent;
title?: string; title?: string;
accent?: LightButtonAccent; accent?: LightButtonAccent;
active?: boolean; active?: boolean;
@ -76,7 +77,7 @@ const StyledButton = styled.button<
export const LightButton = ({ export const LightButton = ({
className, className,
icon: initialIcon, Icon,
title, title,
active = false, active = false,
accent = 'secondary', accent = 'secondary',
@ -84,15 +85,7 @@ export const LightButton = ({
focus = false, focus = false,
onClick, onClick,
}: LightButtonProps) => { }: LightButtonProps) => {
const icon = useMemo(() => { const theme = useTheme();
if (!initialIcon || !React.isValidElement(initialIcon)) {
return null;
}
return React.cloneElement<TablerIconsProps>(initialIcon as any, {
size: 14,
});
}, [initialIcon]);
return ( return (
<StyledButton <StyledButton
@ -103,7 +96,7 @@ export const LightButton = ({
className={className} className={className}
active={active} active={active}
> >
{icon} {!!Icon && <Icon size={theme.icon.size.sm} />}
{title} {title}
</StyledButton> </StyledButton>
); );

View File

@ -22,16 +22,16 @@ export const Default: Story = {
disabled: false, disabled: false,
active: false, active: false,
focus: false, focus: false,
icon: <IconSearch />, Icon: IconSearch,
}, },
argTypes: { argTypes: {
icon: { control: false }, Icon: { control: false },
}, },
decorators: [ComponentDecorator], decorators: [ComponentDecorator],
}; };
export const Catalog: CatalogStory<Story, typeof LightButton> = { export const Catalog: CatalogStory<Story, typeof LightButton> = {
args: { title: 'Filter', icon: <IconSearch /> }, args: { title: 'Filter', Icon: IconSearch },
argTypes: { argTypes: {
accent: { control: false }, accent: { control: false },
disabled: { control: false }, disabled: { control: false },

View File

@ -15,13 +15,17 @@ export type SelectProps<Value extends string | number | null> = {
className?: string; className?: string;
disabled?: boolean; disabled?: boolean;
dropdownScopeId: string; dropdownScopeId: string;
fullWidth?: boolean;
label?: string; label?: string;
onChange?: (value: Value) => void; onChange?: (value: Value) => void;
options: { value: Value; label: string; Icon?: IconComponent }[]; options: { value: Value; label: string; Icon?: IconComponent }[];
value?: Value; value?: Value;
}; };
const StyledControlContainer = styled.div<{ disabled?: boolean }>` const StyledControlContainer = styled.div<{
disabled?: boolean;
fullWidth?: boolean;
}>`
align-items: center; align-items: center;
background-color: ${({ theme }) => theme.background.transparent.lighter}; background-color: ${({ theme }) => theme.background.transparent.lighter};
border: 1px solid ${({ theme }) => theme.border.color.medium}; border: 1px solid ${({ theme }) => theme.border.color.medium};
@ -29,7 +33,7 @@ const StyledControlContainer = styled.div<{ disabled?: boolean }>`
color: ${({ disabled, theme }) => color: ${({ disabled, theme }) =>
disabled ? theme.font.color.tertiary : theme.font.color.primary}; disabled ? theme.font.color.tertiary : theme.font.color.primary};
cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')}; cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};
display: inline-flex; display: ${({ fullWidth }) => (fullWidth ? 'flex' : 'inline-flex')};
gap: ${({ theme }) => theme.spacing(1)}; gap: ${({ theme }) => theme.spacing(1)};
height: ${({ theme }) => theme.spacing(8)}; height: ${({ theme }) => theme.spacing(8)};
justify-content: space-between; justify-content: space-between;
@ -60,6 +64,7 @@ export const Select = <Value extends string | number | null>({
className, className,
disabled, disabled,
dropdownScopeId, dropdownScopeId,
fullWidth,
label, label,
onChange, onChange,
options, options,
@ -72,7 +77,7 @@ export const Select = <Value extends string | number | null>({
const { closeDropdown } = useDropdown({ dropdownScopeId }); const { closeDropdown } = useDropdown({ dropdownScopeId });
const selectControl = ( const selectControl = (
<StyledControlContainer disabled={disabled}> <StyledControlContainer disabled={disabled} fullWidth={fullWidth}>
<StyledControlLabel> <StyledControlLabel>
{!!selectedOption?.Icon && ( {!!selectedOption?.Icon && (
<selectedOption.Icon <selectedOption.Icon

View File

@ -1,10 +1,10 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
const StyledCard = styled.div` const StyledCard = styled.div`
background-color: ${({ theme }) => theme.background.secondary};
border: 1px solid ${({ theme }) => theme.border.color.medium}; border: 1px solid ${({ theme }) => theme.border.color.medium};
border-radius: ${({ theme }) => theme.border.radius.sm}; border-radius: ${({ theme }) => theme.border.radius.sm};
padding: ${({ theme }) => theme.spacing(3)}; color: ${({ theme }) => theme.font.color.secondary};
overflow: hidden;
`; `;
export { StyledCard as Card }; export { StyledCard as Card };

View File

@ -0,0 +1,16 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';
const StyledCardContent = styled.div<{ divider?: boolean }>`
background-color: ${({ theme }) => theme.background.secondary};
padding: ${({ theme }) => theme.spacing(4)};
${({ divider, theme }) =>
divider
? css`
border-bottom: 1px solid ${theme.border.color.medium};
`
: ''}
`;
export { StyledCardContent as CardContent };

View File

@ -0,0 +1,10 @@
import styled from '@emotion/styled';
const StyledCardFooter = styled.div`
background-color: ${({ theme }) => theme.background.primary};
border-top: 1px solid ${({ theme }) => theme.border.color.medium};
font-size: ${({ theme }) => theme.font.size.sm};
padding: ${({ theme }) => theme.spacing(2, 4)};
`;
export { StyledCardFooter as CardFooter };

View File

@ -0,0 +1,11 @@
import styled from '@emotion/styled';
const StyledCardHeader = styled.div`
background-color: ${({ theme }) => theme.background.primary};
border-bottom: 1px solid ${({ theme }) => theme.border.color.medium};
font-size: ${({ theme }) => theme.font.size.sm};
font-weight: ${({ theme }) => theme.font.weight.medium};
padding: ${({ theme }) => theme.spacing(2, 4)};
`;
export { StyledCardHeader as CardHeader };

View File

@ -1,10 +1,31 @@
import { Meta, StoryObj } from '@storybook/react'; import { Meta, StoryObj } from '@storybook/react';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
import { Card } from '../Card'; import { Card } from '../Card';
import { CardContent } from '../CardContent';
import { CardFooter } from '../CardFooter';
import { CardHeader } from '../CardHeader';
const meta: Meta<typeof Card> = { const meta: Meta<typeof Card> = {
title: 'UI/Layout/Card/Card', title: 'UI/Layout/Card/Card',
component: Card, component: Card,
decorators: [ComponentDecorator],
render: (args) => (
<Card {...args}>
<CardHeader>Lorem ipsum</CardHeader>
<CardContent>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id massa
vel odio ullamcorper molestie eu nec ipsum. Sed semper convallis
consectetur.
</CardContent>
<CardFooter>Lorem ipsum</CardFooter>
</Card>
),
argTypes: {
as: { control: false },
theme: { control: false },
},
}; };
export default meta; export default meta;

View File

@ -21,6 +21,7 @@ import { DropdownMenu } from './DropdownMenu';
import { DropdownOnToggleEffect } from './DropdownOnToggleEffect'; import { DropdownOnToggleEffect } from './DropdownOnToggleEffect';
type DropdownProps = { type DropdownProps = {
className?: string;
clickableComponent?: JSX.Element | JSX.Element[]; clickableComponent?: JSX.Element | JSX.Element[];
dropdownComponents: JSX.Element | JSX.Element[]; dropdownComponents: JSX.Element | JSX.Element[];
hotkey?: { hotkey?: {
@ -37,6 +38,7 @@ type DropdownProps = {
}; };
export const Dropdown = ({ export const Dropdown = ({
className,
clickableComponent, clickableComponent,
dropdownComponents, dropdownComponents,
dropdownMenuWidth, dropdownMenuWidth,
@ -97,7 +99,7 @@ export const Dropdown = ({
); );
return ( return (
<div ref={containerRef}> <div ref={containerRef} className={className}>
{clickableComponent && ( {clickableComponent && (
<div ref={refs.setReference} onClick={toggleDropdown}> <div ref={refs.setReference} onClick={toggleDropdown}>
{clickableComponent} {clickableComponent}

View File

@ -0,0 +1,6 @@
import { Account } from '@/accounts/types/Account';
export const mockedAccounts: Account[] = [
{ email: 'thomas@twenty.com', uuid: '0794b782-f52e-48c3-977e-b0f57f90de24' },
{ email: 'thomas@twenty.dev', uuid: 'dc66a7ec-56b2-425b-a8e8-26ff0396c3aa' },
];