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

Add chip component #37846

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
},
{
"path": "./dist/css/bootstrap.css",
"maxSize": "32.5 kB"
"maxSize": "32.75 kB"
},
{
"path": "./dist/css/bootstrap.min.css",
"maxSize": "30.25 kB"
"maxSize": "30.75 kB"
},
{
"path": "./dist/js/bootstrap.bundle.js",
Expand Down
106 changes: 106 additions & 0 deletions scss/_chip.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// stylelint-disable function-disallowed-list

// Base class
//

.chip {
// scss-docs-start chip-css-vars
--#{$prefix}chip-gap: #{$chip-gap};
--#{$prefix}chip-padding-x: #{$chip-padding-x};
--#{$prefix}chip-padding-y: #{$chip-padding-y};
@include rfs($chip-font-size, --#{$prefix}chip-font-size);
--#{$prefix}chip-font-shift: #{$chip-font-shift};
--#{$prefix}chip-font-weight: #{$chip-font-weight};
--#{$prefix}chip-icon-size: #{$chip-icon-size};
--#{$prefix}chip-icon-margin-start: #{$chip-icon-margin-start};
--#{$prefix}chip-close-size: .5rem;
--#{$prefix}chip-close-margin-end: #{$chip-close-margin-end};
--#{$prefix}chip-close-margin-start: #{$chip-close-margin-start};
--#{$prefix}chip-border-width: #{$chip-border-width};
--#{$prefix}chip-border-radius: #{$chip-border-radius};
--#{$prefix}chip-border-color: #{$chip-border-color};
--#{$prefix}chip-active-color: #{$chip-active-color};
--#{$prefix}chip-active-decoration-color: #{$chip-active-decoration-color};
--#{$prefix}chip-disabled-color: #{$chip-disabled-color};
--#{$prefix}chip-outline-color: var(--#{$prefix}link-hover-color);
// scss-docs-end chip-css-vars

display: inline-flex;
gap: var(--#{$prefix}chip-gap);
align-items: center;
padding: subtract(var(--#{$prefix}chip-padding-y), calc(var(--#{$prefix}chip-font-shift) * .5)) var(--#{$prefix}chip-padding-x) add(var(--#{$prefix}chip-padding-y), calc(var(--#{$prefix}chip-font-shift) * .5));
@include font-size(var(--#{$prefix}chip-font-size));
font-weight: var(--#{$prefix}chip-font-weight);
line-height: add(var(--#{$prefix}chip-font-size), .125rem);
color: inherit;
background-color: transparent;
border: var(--#{$prefix}chip-border-width) solid var(--#{$prefix}chip-border-color);
@include border-radius(var(--#{$prefix}chip-border-radius));

img,
svg {
width: var(--#{$prefix}chip-icon-size);
min-width: var(--#{$prefix}chip-icon-size); // Here to avoid weird behavior on wrap
height: var(--#{$prefix}chip-icon-size);
margin: add(calc(-.5 * var(--#{$prefix}chip-icon-size)), var(--#{$prefix}chip-font-shift)) 0 calc(-.5 * var(--#{$prefix}chip-icon-size)) var(--#{$prefix}chip-icon-margin-start);
}

> .btn-close {
width: var(--#{$prefix}chip-close-size);
height: var(--#{$prefix}chip-close-size);
padding: .25em;
}

&[disabled],
&.disabled {
color: var(--#{$prefix}chip-disabled-color);
pointer-events: none;
border-color: var(--#{$prefix}chip-disabled-color);
}
}

// stylelint-disable selector-no-qualifying-type
a.chip,
button.chip,
label.chip {
color: inherit;
text-decoration: none;
cursor: pointer;
// outline-offset: $outline-offset;

&:hover {
border-color: var(--#{$prefix}chip-active-decoration-color);
}

/* &:focus[data-focus-visible-added] {
outline: $outline-width * 1.5 solid var(--#{$prefix}chip-outline-color);
outline-offset: $outline-offset;
} */

&.active,
&:active {
color: var(--#{$prefix}chip-active-color);
background-color: var(--#{$prefix}chip-active-decoration-color);
border-color: var(--#{$prefix}chip-active-decoration-color);

&[disabled],
&.disabled {
background-color: var(--#{$prefix}chip-disabled-color);
border-color: var(--#{$prefix}chip-disabled-color);
}
}
}
// stylelint-enable selector-no-qualifying-type

.chip-sm {
// scss-docs-start chip-sm-css-vars
--#{$prefix}chip-padding-x: #{$chip-padding-x-sm};
--#{$prefix}chip-padding-y: #{$chip-padding-y-sm};
--#{$prefix}chip-font-size: #{$chip-font-size-sm};
--#{$prefix}chip-icon-size: #{$chip-icon-size-sm};
--#{$prefix}chip-icon-margin-start: #{$chip-icon-margin-start-sm};
--#{$prefix}chip-close-margin-end: #{$chip-close-margin-end-sm};
--#{$prefix}chip-close-margin-start: #{$chip-close-margin-start-sm};
// scss-docs-end chip-sm-css-vars
}

32 changes: 32 additions & 0 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,38 @@ $badge-padding-x: .65em !default;
$badge-border-radius: var(--#{$prefix}border-radius) !default;
// scss-docs-end badge-variables

// Chips

// scss-docs-start chip-variables
$chip-gap: map-get($spacers, 1) !default;
$chip-font-shift: $spacer * .1 !default;
$chip-font-weight: $font-weight-normal !default;
$chip-border-width: $border-width !default;
$chip-border-radius: $border-radius !default;

$chip-padding-x: $spacer * .65 !default;
$chip-padding-y: $spacer * .45 !default;
$chip-icon-size: $spacer * 1.2 !default;
$chip-icon-margin-start: -$spacer * .35 !default;
$chip-close-margin-end: -$spacer * .3 !default;
$chip-close-margin-start: $spacer * .2 !default;
$chip-font-size: $font-size-base !default;

$chip-active-color: $component-active-color !default;
$chip-disabled-color: $gray-500 !default;
$chip-border-color: $gray-500 !default;
$chip-active-decoration-color: $component-active-bg !default;
// scss-docs-end chip-variables

// scss-docs-start chip-sm-variables
$chip-padding-x-sm: $spacer * .4 !default;
$chip-padding-y-sm: $spacer * .25 !default;
$chip-icon-size-sm: $spacer !default;
$chip-icon-margin-start-sm: -$spacer * .1 !default;
$chip-close-margin-end-sm: -$spacer * .25 !default;
$chip-close-margin-start-sm: 0 !default;
$chip-font-size-sm: $font-size-sm !default;
// scss-docs-end chip-sm-variables

// Modals

Expand Down
1 change: 1 addition & 0 deletions scss/bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@import "spinners";
@import "offcanvas";
@import "placeholders";
@import "chip";

// Helpers
@import "helpers";
Expand Down
26 changes: 26 additions & 0 deletions scss/forms/_form-check.scss
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,32 @@
filter: none;
opacity: $form-check-btn-check-disabled-opacity;
}

+ .chip {
color: var(--#{$prefix}chip-disabled-color);
pointer-events: none;
border-color: var(--#{$prefix}chip-disabled-color);
}

&:checked + .chip {
color: var(--#{$prefix}chip-active-color);
background-color: var(--#{$prefix}chip-disabled-color);
}
}

&:checked {
+ .chip {
color: var(--bs-chip-active-color);
background-color: var(--bs-chip-active-decoration-color);
border-color: var(--bs-chip-active-decoration-color);
}
}

&:focus-visible {
+ .chip {
outline: 1px * 1.5 solid var(--#{$prefix}chip-outline-color);
outline-offset: .125rem;
}
}
}

Expand Down
Loading
Loading