Skip to content
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

feat(radio-button, radio-button-group): add component tokens #8831

Merged
merged 14 commits into from
Mar 5, 2024
13 changes: 13 additions & 0 deletions packages/calcite-components/src/assets/styles/includes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@
}
}

@mixin outlineNone() {
outline: 2px solid transparent;
outline-offset: 2px;
}

@mixin focusOutset($outline, $outlineOffset) {
outline: var(
#{$outline},
2px solid var(--calcite-ui-focus-color, var(--calcite-color-brand-hover, var(--calcite--color-brand)))
);
outline-offset: var(#{$outlineOffset}, calc(2px * calc(1 - 2 * clamp(0, var(--calcite-offset-invert-focus), 1))));
}

@mixin xButton() {
:host([scale="s"]) {
.x-button {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-radio-button-group-input-message-space: Specifies the spacing of the input message.
*/

:host {
@apply flex flex-col;
display: flex;
flex-direction: column;
}

:host > .item-wrapper {
@apply flex;
display: flex;
max-inline-size: 100vw;
}

:host([layout="horizontal"]) > .item-wrapper {
@apply flex-row flex-wrap;
flex-direction: row;
flex-wrap: wrap;
}

:host([layout="horizontal"][scale="s"]) > .item-wrapper {
@apply gap-x-4;
column-gap: var(--calcite-spacing-xl);
}

:host([layout="horizontal"][scale="m"]) > .item-wrapper {
@apply gap-x-5;
column-gap: var(--calcite-spacing-xxl);
}

:host([layout="horizontal"][scale="l"]) > .item-wrapper {
@apply gap-x-6;
column-gap: #{$calcite-size-24}; // TODO: need new size token for this size
}

:host([layout="vertical"]) > .item-wrapper {
@apply flex-col;
flex-direction: column;
}

:host([scale="s"]) calcite-input-message {
--calcite-input-message-spacing-value: calc(var(--calcite-spacing-xxs) * -1);
--calcite-input-message-spacing-value: calc(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to an -internal- var

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alisonailea --calcite-radio-button-group-input-message-space should be internal? Then a user wouldn't be able to set the spacing for the input-message component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why we'd want folks to adjust the distance between the input message and the control. Are there examples where we see this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only added this because its a var on the input-message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Yeah maybe we can deprecate it there if it isn't. A standalone instance of the component can just be spaced with css on the element.

var(--calcite-radio-button-group-input-message-space, var(--calcite-spacing-xxs)) * -1
);
}

:host([scale="m"]) calcite-input-message {
--calcite-input-message-spacing-value: calc(var(--calcite-spacing-sm) * -1);
--calcite-input-message-spacing-value: calc(
var(--calcite-radio-button-group-input-message-space, var(--calcite-spacing-sm)) * -1
);
}

:host([scale="l"]) calcite-input-message {
--calcite-input-message-spacing-value: calc(var(--calcite-spacing-md) * -1);
--calcite-input-message-spacing-value: calc(
var(--calcite-radio-button-group-input-message-space, var(--calcite-spacing-md)) * -1
);
}

@include form-validation-message();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,97 @@ export const validationMessage_TestOnly = (): string => html`
</calcite-radio-button-group>
</div>
`;

export const theming_TestOnly = (): string => html`
<style>
.container {
display: flex;
flex-direction: column;
width: 400px;
height: 200px;
gap: 20px;
}

calcite-radio-button {
--calcite-radio-button-background-color: orange;
--calcite-radio-button-border-radius: 50%;
--calcite-radio-focus: 2px solid red;
--calcite-radio-button-shadow: 0 0 0 2px blue;
--calcite-radio-button-size: 20px;
}

calcite-radio-button-group {
--calcite-radio-button-group-input-message-spacing-value: 5px;
}
</style>
<div class="container">
<calcite-radio-button-group
layout="horizontal"
name="validation"
required
scale="s"
status="invalid"
validation-icon
validation-message="Please select an option."
>
<calcite-label layout="inline" scale="s">
<calcite-radio-button value="one" scale="s"></calcite-radio-button>
One
</calcite-label>
<calcite-label layout="inline" scale="s">
<calcite-radio-button value="two" scale="s"></calcite-radio-button>
Two
</calcite-label>
<calcite-label layout="inline" scale="s">
<calcite-radio-button value="three" scale="s"></calcite-radio-button>
Three
</calcite-label>
</calcite-radio-button-group>

<calcite-radio-button-group
layout="horizontal"
name="validation"
required
scale="m"
status="invalid"
validation-icon
validation-message="Please select an option."
>
<calcite-label layout="inline" scale="m">
<calcite-radio-button value="one" scale="m"></calcite-radio-button>
One
</calcite-label>
<calcite-label layout="inline" scale="m">
<calcite-radio-button value="two" scale="m"></calcite-radio-button>
Two
</calcite-label>
<calcite-label layout="inline" scale="m">
<calcite-radio-button value="three" scale="m"></calcite-radio-button>
Three
</calcite-label>
</calcite-radio-button-group>

<calcite-radio-button-group
layout="horizontal"
name="validation"
required
scale="l"
status="invalid"
validation-icon
validation-message="Please select an option."
>
<calcite-label layout="inline" scale="l">
<calcite-radio-button value="one" scale="l"></calcite-radio-button>
One
</calcite-label>
<calcite-label layout="inline" scale="l">
<calcite-radio-button value="two" scale="l"></calcite-radio-button>
Two
</calcite-label>
<calcite-label layout="inline" scale="l">
<calcite-radio-button value="three" scale="l"></calcite-radio-button>
Three
</calcite-label>
</calcite-radio-button-group>
</div>
`;
Original file line number Diff line number Diff line change
@@ -1,92 +1,129 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-radio-button-background-color: Specifies the background color of the component.
* @prop --calcite-radio-button-border-radius: Specifies the border radius of the component.
* @prop --calcite-radio-focus: Specifies the focus of the component.
* @prop --calcite-radio-button-shadow: Specifies the shadow of the component.
* @prop --calcite-radio-button-size: Specifies the size of the component.
*/

:host {
@apply block cursor-pointer;
.container {
@apply relative outline-none;
}
.radio {
@apply bg-foreground-1 cursor-pointer focus-base rounded-full transition-default;
box-shadow: inset 0 0 0 1px var(--calcite-color-border-input);
}
display: block;
cursor: pointer;
}

:host([hovered]),
:host(:not([checked])[focused]:not([disabled])) {
.radio {
box-shadow: inset 0 0 0 2px var(--calcite-color-brand);
}
.container {
position: relative;
@include outlineNone();
}

:host([focused]) {
.radio {
@apply focus-outset;
}
.radio {
background-color: var(--calcite-radio-button-background-color, var(--calcite-color-foreground-1));
cursor: pointer;
outline-color: transparent;
border-radius: var(--calcite-radio-button-border-radius, var(--calcite-corner-radius-pill));
transition:
all var(--calcite-animation-timing) ease-in-out 0s,
outline 0s,
outline-offset 0s;
box-shadow: var(--calcite-radio-button-shadow, inset 0 0 0 1px var(--calcite-color-border-input));
}

@include disabled() {
:host([scale="s"]) .radio {
block-size: var(--calcite-radio-button-size, var(--calcite-font-size--2));
max-inline-size: var(--calcite-radio-button-size, var(--calcite-font-size--2));
min-inline-size: var(--calcite-radio-button-size, var(--calcite-font-size--2));
}

:host([scale="m"]) .radio {
block-size: var(--calcite-radio-button-size, var(--calcite-font-size--1));
max-inline-size: var(--calcite-radio-button-size, var(--calcite-font-size--1));
min-inline-size: var(--calcite-radio-button-size, var(--calcite-font-size--1));
}

:host([scale="l"]) .radio {
block-size: var(--calcite-radio-button-size, var(--calcite-font-size-0));
max-inline-size: var(--calcite-radio-button-size, var(--calcite-font-size-0));
min-inline-size: var(--calcite-radio-button-size, var(--calcite-font-size-0));
}

:host([focused]) {
.radio {
@apply opacity-disabled cursor-default;
@include focusOutset("--calcite-radio-focus", "--calcite-internal-radio-focus-offset");
}
}

:host([hovered][disabled]) {
.radio {
box-shadow: inset 0 0 0 1px var(--calcite-color-border-input);
box-shadow: var(--calcite-radio-button-shadow, inset 0 0 0 1px var(--calcite-color-border-input));
}
}

:host([scale="s"]) {
--calcite-radio-size: theme("fontSize.n2");
}
:host([scale="m"]) {
--calcite-radio-size: theme("fontSize.n1");
}
:host([scale="l"]) {
--calcite-radio-size: theme("fontSize.0");
:host([hovered]),
:host(:not([checked])[focused]:not([disabled])) {
.radio {
box-shadow: var(--calcite-radio-button-shadow, inset 0 0 0 2px var(--calcite-color-brand));
}
}

.radio {
block-size: var(--calcite-radio-size);
max-inline-size: var(--calcite-radio-size);
min-inline-size: var(--calcite-radio-size);
@include disabled() {
.radio {
opacity: var(--calcite-opacity-disabled);
cursor: default;
}
}

:host([scale="s"][checked]),
:host([hovered][scale="s"][checked][disabled]) {
.radio {
box-shadow: inset 0 0 0 4px var(--calcite-color-brand);
box-shadow: var(--calcite-radio-button-shadow, inset 0 0 0 4px var(--calcite-color-brand));
}
}

:host([scale="s"][focused][checked]:not([disabled])) {
.radio {
box-shadow:
box-shadow: var(
--calcite-radio-button-shadow,
inset 0 0 0 4px var(--calcite-color-brand),
0 0 0 2px var(--calcite-color-foreground-1);
0 0 0 2px var(--calcite-color-foreground-1)
);
}
}

:host([scale="m"][checked]),
:host([hovered][scale="m"][checked][disabled]) {
.radio {
box-shadow: inset 0 0 0 5px var(--calcite-color-brand);
box-shadow: var(--calcite-radio-button-shadow, inset 0 0 0 5px var(--calcite-color-brand));
}
}

:host([scale="m"][focused][checked]:not([disabled])) {
.radio {
box-shadow:
box-shadow: var(
--calcite-radio-button-shadow,
inset 0 0 0 5px var(--calcite-color-brand),
0 0 0 2px var(--calcite-color-foreground-1);
0 0 0 2px var(--calcite-color-foreground-1)
);
}
}

:host([scale="l"][checked]),
:host([hovered][scale="l"][checked][disabled]) {
.radio {
box-shadow: inset 0 0 0 6px var(--calcite-color-brand);
box-shadow: var(--calcite-radio-button-shadow, inset 0 0 0 6px var(--calcite-color-brand));
}
}

:host([scale="l"][focused][checked]:not([disabled])) {
.radio {
box-shadow:
box-shadow: var(
--calcite-radio-button-shadow,
inset 0 0 0 6px var(--calcite-color-brand),
0 0 0 2px var(--calcite-color-foreground-1);
0 0 0 2px var(--calcite-color-foreground-1)
);
}
}

Expand All @@ -95,12 +132,25 @@
:host([checked][disabled]) {
.radio::after {
content: "";
inline-size: var(--calcite-radio-size);
block-size: var(--calcite-radio-size);
background-color: windowText;
display: block;
}
}

:host([checked][scale="s"]) .radio::after {
inline-size: var(--calcite-radio-button-size, var(--calcite-font-size--2));
block-size: var(--calcite-radio-button-size, var(--calcite-font-size--2));
}

:host([checked][scale="m"]) .radio::after {
inline-size: var(--calcite-radio-button-size, var(--calcite-font-size--1));
block-size: var(--calcite-radio-button-size, var(--calcite-font-size--1));
}

:host([checked][scale="l"]) .radio::after {
inline-size: var(--calcite-radio-button-size, var(--calcite-font-size-0));
block-size: var(--calcite-radio-button-size, var(--calcite-font-size-0));
}
}

@include hidden-form-input();
Expand Down
Loading
Loading