Skip to content

Commit

Permalink
Fix: [IGL-112] Fixed box-sizing & positioning (#629)
Browse files Browse the repository at this point in the history
* Fix: [IGL-112] Fixed box-sizing & positioning
  • Loading branch information
vicky-comeau authored Jan 8, 2024
1 parent 37260f9 commit 736a1b5
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 101 deletions.
6 changes: 6 additions & 0 deletions .changeset/cuddly-buckets-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@igloo-ui/checkbox": patch
"@igloo-ui/radio": patch
---

Fixed checkbox and radio by ensuring the box-sizing is set on the container and all its children. Also fixed line-height and positioning.
37 changes: 19 additions & 18 deletions packages/Checkbox/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const Checkbox: React.FunctionComponent<CheckboxProps> = React.forwardRef(
): void => {
if (onChange) {
onChange(event);

return;
}

Expand All @@ -75,7 +76,7 @@ const Checkbox: React.FunctionComponent<CheckboxProps> = React.forwardRef(

return (
<span
className={cx("ids-form-control", className, {
className={cx("ids-form-control", "ids-form-control-checkbox", className, {
[`ids-form-control--${appearance}`]: appearance !== "default"
})}
>
Expand All @@ -92,23 +93,23 @@ const Checkbox: React.FunctionComponent<CheckboxProps> = React.forwardRef(
onChange={handleOnChange}
{...rest}
/>
{showLabel && (
<label
className={cx("ids-checkbox__label", {
[`ids-checkbox__label--${appearance}`]: appearance !== "default"
})}
htmlFor={htmlFor}
>
{appearance === "completion" && (
<span className="ids-checkbox__box">
<Checkmark size="small" className="ids-checkbox__check" />
</span>
)}
{children && (
<span className="ids-checkbox__label-text">{children}</span>
)}
</label>
)}
{showLabel && (
<label
className={cx("ids-checkbox__label", {
[`ids-checkbox__label--${appearance}`]: appearance !== "default"
})}
htmlFor={htmlFor}
>
{appearance === "completion" && (
<span className="ids-checkbox__box">
<Checkmark size="small" className="ids-checkbox__check" />
</span>
)}
{children && (
<span className="ids-checkbox__label-text">{children}</span>
)}
</label>
)}
</span>
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/Checkbox/src/__snapshots__/Checkbox.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Checkbox It should render a checked state 1`] = `
<DocumentFragment>
<span
class="ids-form-control"
class="ids-form-control ids-form-control-checkbox"
>
<input
checked=""
Expand All @@ -18,7 +18,7 @@ exports[`Checkbox It should render a checked state 1`] = `
exports[`Checkbox It should render a disabled state 1`] = `
<DocumentFragment>
<span
class="ids-form-control"
class="ids-form-control ids-form-control-checkbox"
>
<input
class="ids-checkbox"
Expand All @@ -33,7 +33,7 @@ exports[`Checkbox It should render a disabled state 1`] = `
exports[`Checkbox It should render a indeterminate state 1`] = `
<DocumentFragment>
<span
class="ids-form-control"
class="ids-form-control ids-form-control-checkbox"
>
<input
class="ids-checkbox"
Expand Down
25 changes: 15 additions & 10 deletions packages/Checkbox/src/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
--ids-checkbox-check-width: 0.4rem;
--ids-checkbox-check-height: 0.8rem;
--ids-checkbox-check-border: 0.2rem;
--ids-checkbox-check-left: 0.2rem;
--ids-checkbox-check-top: 0.7rem;
--ids-checkbox-check-color-disabled: #{tokens.$grey-600};
--ids-checkbox-indeterminate-width: 0.6rem;
--ids-checkbox-indeterminate-border: 0.2rem;
Expand All @@ -60,7 +58,7 @@
--ids-checkbox-radius: var(--hop-shape-rounded-sm);
--ids-checkbox-check: var(--hop-neutral-icon-active);
--ids-checkbox-margin: var(--hop-space-inline-sm);
--ids-checkbox-top-space: 0;
--ids-checkbox-top-space: 0.15rem;
--ids-checkbox-box-sizing: border-box;
--ids-checkbox-text: var(--hop-neutral-text);
--ids-checkbox-text-disabled: var(--hop-neutral-text-disabled);
Expand All @@ -77,8 +75,6 @@
--ids-checkbox-check-width: 0.25rem;
--ids-checkbox-check-height: 0.5rem;
--ids-checkbox-check-border: 0.125rem;
--ids-checkbox-check-left: 0.0625rem;
--ids-checkbox-check-top: 0.4375rem;
--ids-checkbox-check-color: var(--hop-neutral-icon-active);
--ids-checkbox-check-color-disabled: var(--hop-neutral-icon-disabled);
--ids-checkbox-indeterminate-width: 0.5625rem;
Expand All @@ -88,7 +84,7 @@
--ids-checkbox-completion-size: 1.5rem;
--ids-checkbox-completion-background-disabled: var(--hop-neutral-surface-disabled);
--ids-checkbox-completion-border-disabled: var(--hop-neutral-border-disabled);
--ids-checkbox-completion-check-size: 0.75rem;
--ids-checkbox-completion-check-size: 1rem;
--ids-checkbox-completion-check-color-hover: transparent;
--ids-checkbox-completion-check-color-selected: var(--hop-neutral-icon-active);
--ids-checkbox-completion-check-color-default: transparent;
Expand Down Expand Up @@ -119,11 +115,19 @@
align-items: flex-start;
}

.ids-form-control-checkbox {
&,
& * {
box-sizing: var(--ids-checkbox-box-sizing);
}
}

.ids-checkbox__label {
color: var(--ids-checkbox-text);
font-family: var(--ids-checkbox-font-family);
font-size: var(--ids-checkbox-font-size);
font-weight: var(--ids-checkbox-font-weight);
color: var(--ids-checkbox-text);
line-height: var(--ids-checkbox-line-height);

&--completion {
align-items: center;
Expand All @@ -132,6 +136,7 @@
}

.ids-checkbox__label-text {
display: block;
padding-left: var(--ids-checkbox-margin);
}

Expand All @@ -148,7 +153,6 @@
border: var(--ids-checkbox-one-px) solid var(--ids-checkbox-border);
border-radius: var(--ids-checkbox-radius);
background: var(--ids-checkbox-background);
box-sizing: var(--ids-checkbox-box-sizing);
transition: background 0.05s ease-in-out;

&:hover{
Expand Down Expand Up @@ -208,8 +212,9 @@
@extend %check;

display: block;
left: var(--ids-checkbox-check-left);
top: var(--ids-checkbox-check-top);
left: 0;
top: 50%;
translate: 50% 0;
animation: check-animation ease-out 0.25s 0.15s both;
}

Expand Down
136 changes: 68 additions & 68 deletions packages/Radio/src/Radio.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
import * as React from 'react';
import cx from 'classnames';
import * as React from "react";
import cx from "classnames";

import './radio.scss';
import "./radio.scss";

export interface RadioProps extends React.ComponentPropsWithRef<'input'> {
/** The content to display inside the label */
children?: React.ReactNode;
/** Add a specific class to the checkbox */
className?: string;
/** Add a data-test tag for automated tests */
dataTest?: string;
/** Indicates the ID of the element that is controlled by the checkbox */
htmlFor: string;
/** Changes the size of label */
small?: boolean;
/** Modifies true/false value of the native checkbox */
checked?: boolean;
/** Modifies the native disabled state of the native checkbox */
disabled?: boolean;
/** The content to display to help users */
helperText?: string;
/** Function called when the value changes */
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
export interface RadioProps extends React.ComponentPropsWithRef<"input"> {
/** The content to display inside the label */
children?: React.ReactNode;
/** Add a specific class to the checkbox */
className?: string;
/** Add a data-test tag for automated tests */
dataTest?: string;
/** Indicates the ID of the element that is controlled by the checkbox */
htmlFor: string;
/** Changes the size of label */
small?: boolean;
/** Modifies true/false value of the native checkbox */
checked?: boolean;
/** Modifies the native disabled state of the native checkbox */
disabled?: boolean;
/** The content to display to help users */
helperText?: string;
/** Function called when the value changes */
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
}

const Radio: React.FunctionComponent<RadioProps> = React.forwardRef(
(
{
children,
className,
dataTest,
htmlFor,
onChange,
helperText,
small,
checked,
disabled,
...rest
}: RadioProps,
ref: React.Ref<HTMLInputElement>,
) => {
const classes = cx('ids-radio', className, {
'ids-radio--small': small,
});
(
{
children,
className,
dataTest,
htmlFor,
onChange,
helperText,
small,
checked,
disabled,
...rest
}: RadioProps,
ref: React.Ref<HTMLInputElement>
) => {
const classes = cx("ids-radio", className, {
"ids-radio--small": small
});

return (
<span
className={cx('ids-form-control', {
'has-description': helperText,
})}
>
<input
ref={ref}
id={htmlFor}
className={classes}
data-test={dataTest}
checked={checked}
disabled={disabled}
type="radio"
onChange={onChange}
{...rest}
/>
{children && (
<label className="ids-radio__label" htmlFor={htmlFor}>
{children}
{helperText && (
<span className="ids-radio__description">{helperText}</span>
)}
</label>
)}
</span>
);
},
return (
<span
className={cx("ids-form-control", "ids-form-control-radio", {
"has-description": helperText
})}
>
<input
ref={ref}
id={htmlFor}
className={classes}
data-test={dataTest}
checked={checked}
disabled={disabled}
type="radio"
onChange={onChange}
{...rest}
/>
{children && (
<label className="ids-radio__label" htmlFor={htmlFor}>
{children}
{helperText && (
<span className="ids-radio__description">{helperText}</span>
)}
</label>
)}
</span>
);
}
);

export default Radio;
22 changes: 20 additions & 2 deletions packages/Radio/src/radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
--ids-radio-font-size: #{tokens.$font-size-4};
--ids-radio-font-size-small: #{tokens.$font-size-3};
--ids-radio-font-size-description: #{tokens.$font-size-3};
--ids-radio-line-height: normal;
--ids-radio-line-height-small: normal;
--ids-radio-text: #{tokens.$grey-800};
--ids-radio-text-description: #{tokens.$grey-600};
--ids-radio-description-padding: #{tokens.$space-1};
--ids-radio-padding: #{tokens.$space-2};
--ids-radio-margin: .2rem 0 0;
--ids-radio-margin-small: .12rem 0 0;
--ids-radio-size: #{tokens.$font-size-4};
--ids-radio-check: #{tokens.$samoyed};
--ids-radio-border: #{tokens.$grey-400};
Expand All @@ -35,11 +38,14 @@
--ids-radio-font-size: var(--hop-body-md-font-size);
--ids-radio-font-size-small: var(--hop-sm-font-size);
--ids-radio-font-size-description: var(--hop-body-sm-font-size);
--ids-radio-line-height: var(--hop-body-md-line-height);
--ids-radio-line-height-small: var(--hop-body-sm-line-height);
--ids-radio-text: var(--hop-neutral-text);
--ids-radio-text-description: var(--hop-neutral-text-weak);
--ids-radio-description-padding: 0;
--ids-radio-padding: var(--hop-space-inline-sm);
--ids-radio-margin: calc(var(--hop-space-inline-xs) / 2) 0 0;
--ids-radio-margin: var(--hop-space-stack-xs) 0 0;
--ids-radio-margin-small: 0.15rem 0 0;
--ids-radio-size: 1rem;
--ids-radio-check: var(--hop-neutral-surface);
--ids-radio-check-size: .5rem;
Expand Down Expand Up @@ -74,11 +80,19 @@
align-items: flex-start;
}

.ids-form-control-radio {
&,
& * {
box-sizing: border-box;
}
}

.ids-radio__label {
font-family: var(--ids-radio-font-family);
font-size: var(--ids-radio-font-size);
font-weight: var(--ids-radio-font-weight);
color: var(--ids-radio-text);
line-height: var(--ids-radio-line-height);
padding-left: var(--ids-radio-padding);
}

Expand All @@ -95,7 +109,6 @@
border: var(--ids-radio-border-size, .1rem) solid var(--ids-radio-border);
border-radius: 50%;
background: var(--ids-radio-background);
box-sizing: border-box;
transition: background 0.05s ease-in-out;

&:checked {
Expand Down Expand Up @@ -151,8 +164,13 @@
}
}

&--small {
margin: var(--ids-radio-margin-small);
}

&--small + &__label {
font-size: var(--ids-radio-font-size-small);
line-height: var(--ids-radio-line-height-small);
}
}

Expand Down

0 comments on commit 736a1b5

Please sign in to comment.