-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add account name type selection and radio group component for ISV con…
…figuration
- Loading branch information
1 parent
ce580c2
commit 36b2bd0
Showing
5 changed files
with
172 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { useId } from 'react'; | ||
import styled from 'styled-components'; | ||
import { spacing } from '@scality/core-ui/dist/spacing'; | ||
|
||
type RadioOption = { | ||
value: string; | ||
label: string; | ||
description?: string; | ||
}; | ||
|
||
type RadioGroupProps = { | ||
options: RadioOption[]; | ||
value: string; | ||
onChange: (value: string) => void; | ||
name?: string; | ||
direction?: 'horizontal' | 'vertical'; | ||
disabled?: boolean; | ||
}; | ||
|
||
const RadioContainer = styled.div<{ direction: 'horizontal' | 'vertical' }>` | ||
display: flex; | ||
flex-direction: ${(props) => | ||
props.direction === 'horizontal' ? 'row' : 'column'}; | ||
gap: ${spacing.r8}; | ||
`; | ||
|
||
const RadioWrapper = styled.label` | ||
display: flex; | ||
align-items: flex-start; | ||
gap: ${spacing.r8}; | ||
cursor: pointer; | ||
padding: ${spacing.r4}; | ||
padding-left: 0; | ||
padding-bottom: ${spacing.r8}; | ||
border-radius: 4px; | ||
&[data-disabled='true'] { | ||
cursor: not-allowed; | ||
opacity: 0.5; | ||
} | ||
`; | ||
|
||
const RadioInput = styled.input` | ||
margin-top: 4px; | ||
margin-left: 0; | ||
cursor: inherit; | ||
`; | ||
|
||
const RadioContent = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${spacing.r4}; | ||
`; | ||
|
||
const RadioLabel = styled.span` | ||
color: ${(props) => props.theme.textPrimary}; | ||
font-weight: 500; | ||
`; | ||
|
||
const RadioDescription = styled.span` | ||
color: ${(props) => props.theme.textSecondary}; | ||
font-size: 0.875rem; | ||
`; | ||
|
||
export const RadioGroup = ({ | ||
options, | ||
value, | ||
onChange, | ||
name, | ||
direction = 'vertical', | ||
disabled = false, | ||
}: RadioGroupProps) => { | ||
const groupId = useId(); | ||
const groupName = name || groupId; | ||
|
||
return ( | ||
<RadioContainer direction={direction}> | ||
{options.map((option) => ( | ||
<RadioWrapper key={option.value} data-disabled={disabled}> | ||
<RadioInput | ||
type="radio" | ||
name={groupName} | ||
value={option.value} | ||
checked={value === option.value} | ||
onChange={(e) => onChange(e.target.value)} | ||
disabled={disabled} | ||
/> | ||
<RadioContent> | ||
<RadioLabel>{option.label}</RadioLabel> | ||
{option.description && ( | ||
<RadioDescription>{option.description}</RadioDescription> | ||
)} | ||
</RadioContent> | ||
</RadioWrapper> | ||
))} | ||
</RadioContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters