-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix noninteractive toggle #8383
Changes from all commits
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 |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import styled from '@emotion/styled'; | ||
import { useTheme } from '@emotion/react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import { IconComponent, CardContent } from 'twenty-ui'; | ||
import { ReactNode } from 'react'; | ||
import { useId } from 'react'; | ||
import { CardContent, IconComponent, Toggle } from 'twenty-ui'; | ||
|
||
type SettingsOptionCardContentProps = { | ||
Icon?: IconComponent; | ||
title: string; | ||
title: React.ReactNode; | ||
description: string; | ||
onClick: () => void; | ||
children: ReactNode; | ||
divider?: boolean; | ||
checked: boolean; | ||
onChange: (checked: boolean) => void; | ||
}; | ||
|
||
const StyledCardContent = styled(CardContent)` | ||
align-items: center; | ||
display: flex; | ||
gap: ${({ theme }) => theme.spacing(4)}; | ||
cursor: pointer; | ||
position: relative; | ||
|
||
Comment on lines
20
to
+21
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. logic: cursor: pointer without click handler may be misleading to users |
||
&:hover { | ||
background: ${({ theme }) => theme.background.transparent.lighter}; | ||
|
@@ -47,28 +48,48 @@ const StyledIcon = styled.div` | |
min-width: ${({ theme }) => theme.icon.size.md}; | ||
`; | ||
|
||
const StyledToggle = styled(Toggle)` | ||
margin-left: auto; | ||
`; | ||
|
||
const StyledCover = styled.span` | ||
cursor: pointer; | ||
inset: 0; | ||
position: absolute; | ||
`; | ||
|
||
export const SettingsOptionCardContent = ({ | ||
Icon, | ||
title, | ||
description, | ||
onClick, | ||
children, | ||
divider, | ||
checked, | ||
onChange, | ||
}: SettingsOptionCardContentProps) => { | ||
const theme = useTheme(); | ||
|
||
const toggleId = useId(); | ||
|
||
return ( | ||
<StyledCardContent onClick={onClick} divider={divider}> | ||
<StyledCardContent divider={divider}> | ||
{Icon && ( | ||
<StyledIcon> | ||
<Icon size={theme.icon.size.md} stroke={theme.icon.stroke.md} /> | ||
</StyledIcon> | ||
)} | ||
|
||
<div> | ||
<StyledTitle>{title}</StyledTitle> | ||
<StyledTitle> | ||
<label htmlFor={toggleId}> | ||
{title} | ||
|
||
<StyledCover /> | ||
</label> | ||
</StyledTitle> | ||
<StyledDescription>{description}</StyledDescription> | ||
</div> | ||
{children} | ||
|
||
<StyledToggle id={toggleId} value={checked} onChange={onChange} /> | ||
</StyledCardContent> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,21 @@ import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState'; | |
import { SettingsOptionCardContent } from '@/settings/components/SettingsOptionCardContent'; | ||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar'; | ||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; | ||
import styled from '@emotion/styled'; | ||
import { useRecoilState } from 'recoil'; | ||
import { Card, IconLink, Toggle } from 'twenty-ui'; | ||
import { Card, IconLink, isDefined } from 'twenty-ui'; | ||
import { useUpdateWorkspaceMutation } from '~/generated/graphql'; | ||
|
||
const StyledToggle = styled(Toggle)` | ||
margin-left: auto; | ||
`; | ||
|
||
export const SettingsSecurityOptionsList = () => { | ||
const { enqueueSnackBar } = useSnackBar(); | ||
|
||
const [currentWorkspace, setCurrentWorkspace] = useRecoilState( | ||
currentWorkspaceState, | ||
); | ||
if (!isDefined(currentWorkspace)) { | ||
throw new Error( | ||
'The current workspace must be defined to edit its security options.', | ||
); | ||
} | ||
|
||
const [updateWorkspace] = useUpdateWorkspaceMutation(); | ||
|
||
|
@@ -49,12 +49,11 @@ export const SettingsSecurityOptionsList = () => { | |
Icon={IconLink} | ||
title="Invite by Link" | ||
description="Allow the invitation of new users by sharing an invite link." | ||
onClick={() => | ||
handleChange(!currentWorkspace?.isPublicInviteLinkEnabled) | ||
checked={currentWorkspace.isPublicInviteLinkEnabled} | ||
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. @Devessier I'm encountering a problem with this implementation. Since we need to use inputs other than a checkbox, we should use a slot instead of a prop. https://www.figma.com/design/xt8O9mFeLl46C5InWwoMrN/Twenty?node-id=42308-234697&t=YrBrHCCvLIyihv7X-4 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. Great point. We chose to restrict minimize the API surface with @charlesBochet as all Cards were relying on a Toggle component. We can modify the API have one version for toggles and one for inputs, etc. 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. WDYT of this implementation: We keep the label implementation with the flexibility to use custom input in the card. 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.
I didn't saw the answer 😅 |
||
onChange={() => | ||
handleChange(!currentWorkspace.isPublicInviteLinkEnabled) | ||
} | ||
> | ||
<StyledToggle value={currentWorkspace?.isPublicInviteLinkEnabled} /> | ||
</SettingsOptionCardContent> | ||
/> | ||
</Card> | ||
); | ||
}; |
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.
style: Unnecessary arrow function wrapper. Pass handleContactAutoCreationToggle directly as the onChange prop.