Skip to content

Commit

Permalink
feat(fields): add isReadOnly prop on multiRadio component and add cus…
Browse files Browse the repository at this point in the history
…tom style for plaintext
  • Loading branch information
claire2212 committed Sep 25, 2023
1 parent a22f2b4 commit 7b903cc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/assets/stylesheets/rsuite-override.css
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ label:hover .rs-checkbox-wrapper .rs-checkbox-inner:before {
line-height: 17px;
}

.rs-radio:hover .rs-radio-inner:before {
border-color: var(--charcoal);
}

/* form */
.rs-form:not(.rs-form-inline) .rs-form-group:not(:last-child) {
margin-bottom: 32px;
Expand Down Expand Up @@ -700,3 +704,7 @@ label:hover .rs-checkbox-wrapper .rs-checkbox-inner:before {
height: 100px !important;
background: white !important;
}

.rs-plaintext {
font-size: 13px !important;
}
34 changes: 33 additions & 1 deletion src/fields/MultiRadio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type MultiRadioProps<OptionValue extends OptionValueType = string> = {
isInline?: boolean | undefined
isLabelHidden?: boolean | undefined
isLight?: boolean | undefined
isReadOnly?: boolean
isUndefinedWhenDisabled?: boolean | undefined
label: string
name: string
Expand All @@ -37,6 +38,7 @@ export function MultiRadio<OptionValue extends OptionValueType = string>({
isInline = false,
isLabelHidden = false,
isLight = false,
isReadOnly = false,
isUndefinedWhenDisabled = false,
label,
name,
Expand Down Expand Up @@ -75,14 +77,15 @@ export function MultiRadio<OptionValue extends OptionValueType = string>({
legend={label}
style={style}
>
<Box key={key} $hasError={hasError} $isInline={isInline}>
<Box key={key} $hasError={hasError} $isInline={isInline} $isReadOnly={isReadOnly}>
{options.map(option => (
<Radio
key={JSON.stringify(option.value)}
checked={equals(option.value, value)}
disabled={disabled}
name={name}
onChange={(_: any, isChecked: boolean) => handleChange(option.value, isChecked)}
readOnly={isReadOnly}
>
{option.label}
</Radio>
Expand All @@ -97,6 +100,7 @@ export function MultiRadio<OptionValue extends OptionValueType = string>({
const Box = styled.div<{
$hasError: boolean
$isInline: boolean
$isReadOnly: boolean
}>`
color: ${p => p.theme.color.gunMetal};
display: flex;
Expand Down Expand Up @@ -136,4 +140,32 @@ const Box = styled.div<{
margin-left: 12px;
}
`}
${p =>
p.$isReadOnly &&
css`
.rs-radio {
.rs-radio-checker {
label {
cursor: not-allowed;
.rs-radio-wrapper [type='radio'] {
cursor: not-allowed;
}
}
}
}
.rs-radio:not(.rs-radio-checked):hover .rs-radio-inner:before {
border-color: ${p.theme.color.lightGray};
}
.rs-radio:not(.rs-radio-checked) .rs-radio-inner:before {
background-color: ${p.theme.color.white};
}
.rs-radio:not(.rs-radio-checked) {
.rs-radio-checker {
label {
color: ${p.theme.color.slateGray};
}
}
}
`}
`
13 changes: 11 additions & 2 deletions stories/fields/MultiRadio.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ export function _MultiRadio(props: MultiRadioProps) {

return (
<>
<MultiRadio {...props} onChange={controlledOnChange} value={controlledValue} />
<div style={{ marginBottom: '32px' }}>
<MultiRadio {...props} onChange={controlledOnChange} value={controlledValue} />

{outputValue !== '∅' && <Output value={outputValue} />}
{outputValue !== '∅' && <Output value={outputValue} />}
</div>
<MultiRadio
{...props}
isReadOnly
label="Multiradio in readOnly mode"
onChange={controlledOnChange}
value="FIRST_OPTION"
/>
</>
)
}
11 changes: 11 additions & 0 deletions stories/fields/TextInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ export function _TextInput(props: TextInputProps) {
placeholder="A text input placeholder"
size={Size.LARGE}
/>

<div style={{ marginTop: '32px' }}>
<TextInput
label="A text input with plaintext prop"
name="myTextInputWithPlaintextProp"
placeholder="A text input placeholder"
plaintext
size={Size.LARGE}
value="Plain text value"
/>
</div>
</Showcase>
</>
)
Expand Down

0 comments on commit 7b903cc

Please sign in to comment.