Skip to content

Commit

Permalink
Inherit link color in components that support validation states (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkudrna committed Nov 27, 2024
1 parent d288c21 commit 810dee6
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
40 changes: 35 additions & 5 deletions src/components/CheckboxField/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ React.createElement(() => {
return (
<CheckboxField
checked={agree}
label="I agree"
label={(
<>
I have read and agree with
{' '}
<TextLink href="#" label="terms and conditions" />
</>
)}
onChange={() => setAgree(!agree)}
/>
);
Expand Down Expand Up @@ -132,20 +138,44 @@ React.createElement(() => {
<>
<CheckboxField
checked={agree}
label="I have read and agree with terms and conditions"
label={(
<>
I have read and agree with
{' '}
<TextLink href="#" label="terms and conditions" />
</>
)}
onChange={() => setAgree(!agree)}
validationState="valid"
/>
<CheckboxField
checked={agree}
label="I have read and agree with terms and conditions"
label={(
<>
I have read and agree with
{' '}
<TextLink href="#" label="terms and conditions" />
</>
)}
onChange={() => setAgree(!agree)}
validationState="warning"
validationText="Please wait 10 minutes until we verify your data."
validationText={(
<>
Please wait 10 minutes until we verify your data.
{' '}
<TextLink href="#" label="Cancel" />
</>
)}
/>
<CheckboxField
checked={agree}
label="I have read and agree with terms and conditions"
label={(
<>
I have read and agree with
{' '}
<TextLink href="#" label="terms and conditions" />
</>
)}
onChange={() => setAgree(!agree)}
required
validationState="invalid"
Expand Down
16 changes: 14 additions & 2 deletions src/components/TextField/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,13 @@ have.
label="User name"
onChange={() => {}}
validationState="warning"
validationText="Account with this name already exists, pick a different one."
validationText={(
<>
Account with this name already exists, pick a different one.
{' '}
<TextLink href="#" label="Forgot your password?" />
</>
)}
value="joe"
required
/>
Expand All @@ -411,7 +417,13 @@ have.
label="User name"
onChange={() => {}}
validationState="warning"
validationText="Account with this name already exists, pick a different one."
validationText={(
<>
Account with this name already exists, pick a different one.
{' '}
<TextLink href="#" label="Forgot your password?" />
</>
)}
variant="filled"
value="joe"
required
Expand Down
10 changes: 9 additions & 1 deletion src/components/Toggle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ React.createElement(() => {
label="Listen in studio quality"
onChange={() => setStudioQuality(!studioQuality)}
validationState="invalid"
validationText="Please upgrade your plan to make this option available."
validationText={(
<>
Please
{' '}
<TextLink href="#" label="upgrade your plan" />
{' '}
to make this option available.
</>
)}
/>
</>
);
Expand Down
19 changes: 19 additions & 0 deletions src/styles/theme/_form-fields.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ $horizontal-label-vertical-alignment: var(--rui-FormField--horizontal__label__ve
$horizontal-field-vertical-alignment: var(--rui-FormField--horizontal__field__vertical-alignment);
$horizontal-full-width-label-width: var(--rui-FormField--horizontal--full-width__label__width);

// Form fields: links in validation states
$link-validation-colors: (
invalid: (
default: var(--rui-color-feedback-success),
hover: var(--rui-color-feedback-success-hover),
active: var(--rui-color-feedback-success-active),
),
valid: (
default: var(--rui-color-feedback-valid),
hover: var(--rui-color-feedback-valid-hover),
active: var(--rui-color-feedback-valid-active),
),
warning: (
default: var(--rui-color-feedback-warning),
hover: var(--rui-color-feedback-warning-hover),
active: var(--rui-color-feedback-warning-active),
),
);

// Form fields: disabled state
$disabled-cursor: var(--rui-FormField--disabled__cursor);
$disabled-opacity: var(--rui-FormField--disabled__opacity);
Expand Down
6 changes: 5 additions & 1 deletion src/styles/tools/form-fields/_variants.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
+ "Choose one of #{map.keys(settings.$themeable-variant-states)}.";
}

$themeable-states: map.get(map.get(settings.$themeable-variant-states, $type), $variant);
$themeable-states: map.get(settings.$themeable-variant-states, $type, $variant);

@if list.index($themeable-states, "hover") {
@include _generate-custom-properties($type, $variant, "default");
Expand Down Expand Up @@ -143,5 +143,9 @@
}

@mixin validation($variant) {
--rui-local-link-color: map.get(theme.$link-validation-colors, $variant, default);
--rui-local-link-color-hover: map.get(theme.$link-validation-colors, $variant, hover);
--rui-local-link-color-active: map.get(theme.$link-validation-colors, $variant, active);

@include _get-theme(validation, $variant);
}

0 comments on commit 810dee6

Please sign in to comment.