Skip to content

Commit

Permalink
refactor: styles refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Nov 3, 2022
1 parent 312ba7e commit de0d067
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
56 changes: 42 additions & 14 deletions src/Form/_bootstrap-custom-forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
&:checked ~ .custom-control-label::before {
color: $custom-control-indicator-checked-color;
border-color: $custom-control-indicator-checked-border-color;

@include gradient-bg($custom-control-indicator-checked-bg);
@include box-shadow($custom-control-indicator-checked-box-shadow);
}
Expand All @@ -40,7 +41,9 @@
// the mixin is not used here to make sure there is feedback
@if $enable-shadows {
box-shadow: $input-box-shadow, $custom-control-indicator-focus-box-shadow;
} @else {
}

@else {
box-shadow: $custom-control-indicator-focus-box-shadow;
}
}
Expand All @@ -53,6 +56,7 @@
color: $custom-control-indicator-active-color;
background-color: $custom-control-indicator-active-bg;
border-color: $custom-control-indicator-active-border-color;

@include box-shadow($custom-control-indicator-active-box-shadow);
}

Expand Down Expand Up @@ -92,6 +96,7 @@
content: "";
background-color: $custom-control-indicator-bg;
border: $custom-control-indicator-border-width solid $custom-control-indicator-border-color;

@include box-shadow($custom-control-indicator-box-shadow);
}

Expand Down Expand Up @@ -127,9 +132,11 @@
.custom-control-input:indeterminate ~ .custom-control-label {
&::before {
border-color: $custom-checkbox-indicator-indeterminate-border-color;

@include gradient-bg($custom-checkbox-indicator-indeterminate-bg);
@include box-shadow($custom-checkbox-indicator-indeterminate-box-shadow);
}

&::after {
background-image: escape-svg($custom-checkbox-indicator-icon-indeterminate);
}
Expand All @@ -139,6 +146,7 @@
&:checked ~ .custom-control-label::before {
@include gradient-bg($custom-control-indicator-checked-disabled-bg);
}

&:indeterminate ~ .custom-control-label::before {
@include gradient-bg($custom-control-indicator-checked-disabled-bg);
}
Expand Down Expand Up @@ -186,13 +194,16 @@
}

&::after {
// stylelint-disable-next-line max-line-length
top: add(calc((#{$font-size-base} * #{$line-height-base} - #{$custom-control-indicator-size}) * .5), calc(#{$custom-control-indicator-border-width} * 2));
// stylelint-disable-next-line max-line-length
left: add(calc(-1 * (#{$custom-switch-width} + #{$custom-control-gutter})), calc(#{$custom-control-indicator-border-width} * 2));
width: $custom-switch-indicator-size;
height: $custom-switch-indicator-size;
background-color: $custom-control-indicator-border-color;
// stylelint-disable-next-line property-disallowed-list
border-radius: $custom-switch-indicator-border-radius;

@include transition(transform .15s ease-in-out, $custom-forms-transition);
}
}
Expand Down Expand Up @@ -222,25 +233,30 @@
display: inline-block;
width: 100%;
height: $custom-select-height;
// stylelint-disable-next-line max-line-length
padding: $custom-select-padding-y ($custom-select-padding-x + $custom-select-indicator-padding) $custom-select-padding-y $custom-select-padding-x;
font-family: $custom-select-font-family;
@include font-size($custom-select-font-size);
font-weight: $custom-select-font-weight;
line-height: $custom-select-line-height;
color: $custom-select-color;
vertical-align: middle;
background: $custom-select-bg $custom-select-background;
border: $custom-select-border-width solid $custom-select-border-color;
@include border-radius($custom-select-border-radius, 0);
@include box-shadow($custom-select-box-shadow);
appearance: none;

@include font-size($custom-select-font-size);
@include border-radius($custom-select-border-radius,0);
@include box-shadow($custom-select-box-shadow);

&:focus {
border-color: $custom-select-focus-border-color;
outline: 0;

@if $enable-shadows {
@include box-shadow($custom-select-box-shadow, $custom-select-focus-box-shadow);
} @else {
}

@else {
// Avoid using mixin so we can pass custom focus shadow properly
box-shadow: $custom-select-focus-box-shadow;
}
Expand Down Expand Up @@ -285,6 +301,7 @@
padding-top: $custom-select-padding-y-sm;
padding-bottom: $custom-select-padding-y-sm;
padding-left: $custom-select-padding-x-sm;

@include font-size($custom-select-font-size-sm);
}

Expand All @@ -293,6 +310,7 @@
padding-top: $custom-select-padding-y-lg;
padding-bottom: $custom-select-padding-y-lg;
padding-left: $custom-select-padding-x-lg;

@include font-size($custom-select-font-size-lg);
}

Expand Down Expand Up @@ -355,6 +373,7 @@
color: $custom-file-color;
background-color: $custom-file-bg;
border: $custom-file-border-width solid $custom-file-border-color;

@include border-radius($custom-file-border-radius);
@include box-shadow($custom-file-box-shadow);

Expand All @@ -370,8 +389,9 @@
line-height: $custom-file-line-height;
color: $custom-file-button-color;
content: "Browse";
@include gradient-bg($custom-file-button-bg);
border-left: inherit;

@include gradient-bg($custom-file-button-bg);
@include border-radius(0 $custom-file-border-radius $custom-file-border-radius 0);
}
}
Expand All @@ -395,8 +415,8 @@
// Pseudo-elements must be split across multiple rulesets to have an effect.
// No box-shadow() mixin for focus accessibility.
&::-webkit-slider-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
&::-moz-range-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
&::-ms-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
&::-moz-range-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
&::-ms-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
}

&::-moz-focus-outer {
Expand All @@ -407,12 +427,13 @@
width: $custom-range-thumb-width;
height: $custom-range-thumb-height;
margin-top: calc((#{$custom-range-track-height} - #{$custom-range-thumb-height}) * .5); // Webkit specific
@include gradient-bg($custom-range-thumb-bg);
border: $custom-range-thumb-border;
appearance: none;

@include gradient-bg($custom-range-thumb-bg);
@include border-radius($custom-range-thumb-border-radius);
@include box-shadow($custom-range-thumb-box-shadow);
@include transition($custom-forms-transition);
appearance: none;

&:active {
@include gradient-bg($custom-range-thumb-active-bg);
Expand All @@ -426,19 +447,21 @@
cursor: $custom-range-track-cursor;
background-color: $custom-range-track-bg;
border-color: transparent;

@include border-radius($custom-range-track-border-radius);
@include box-shadow($custom-range-track-box-shadow);
}

&::-moz-range-thumb {
width: $custom-range-thumb-width;
height: $custom-range-thumb-height;
@include gradient-bg($custom-range-thumb-bg);
border: $custom-range-thumb-border;
appearance: none;

@include gradient-bg($custom-range-thumb-bg);
@include border-radius($custom-range-thumb-border-radius);
@include box-shadow($custom-range-thumb-box-shadow);
@include transition($custom-forms-transition);
appearance: none;

&:active {
@include gradient-bg($custom-range-thumb-active-bg);
Expand All @@ -452,6 +475,7 @@
cursor: $custom-range-track-cursor;
background-color: $custom-range-track-bg;
border-color: transparent; // Firefox specific?

@include border-radius($custom-range-track-border-radius);
@include box-shadow($custom-range-track-box-shadow);
}
Expand All @@ -462,12 +486,13 @@
margin-top: 0; // Edge specific
margin-right: $custom-range-thumb-focus-box-shadow-width; // Workaround that overflowed box-shadow is hidden.
margin-left: $custom-range-thumb-focus-box-shadow-width; // Workaround that overflowed box-shadow is hidden.
@include gradient-bg($custom-range-thumb-bg);
border: $custom-range-thumb-border;
appearance: none;

@include gradient-bg($custom-range-thumb-bg);
@include border-radius($custom-range-thumb-border-radius);
@include box-shadow($custom-range-thumb-box-shadow);
@include transition($custom-forms-transition);
appearance: none;

&:active {
@include gradient-bg($custom-range-thumb-active-bg);
Expand All @@ -482,17 +507,20 @@
background-color: transparent;
border-color: transparent;
border-width: calc(#{$custom-range-thumb-height} * .5);

@include box-shadow($custom-range-track-box-shadow);
}

&::-ms-fill-lower {
background-color: $custom-range-track-bg;

@include border-radius($custom-range-track-border-radius);
}

&::-ms-fill-upper {
margin-right: 15px; // arbitrary?
background-color: $custom-range-track-bg;

@include border-radius($custom-range-track-border-radius);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Form/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ $custom-control-label-disabled-color: var(--pgn-form-custom-control-label-color-
$custom-control-indicator-checked-color: #0A3055 !default;
$custom-control-indicator-checked-bg: #0A3055 !default;
$custom-control-indicator-checked-disabled-bg: var(--pgn-form-custom-control-indicator-checked-bg-disabled) !default;
// stylelint-disable-next-line max-line-length
$custom-control-indicator-checked-box-shadow: var(--pgn-form-custom-control-indicator-checked-box-shadow-base) !default;
// stylelint-disable-next-line max-line-length
$custom-control-indicator-checked-border-color: var(--pgn-form-custom-control-indicator-checked-border-color-base) !default;

$custom-control-indicator-focus-box-shadow: var(--pgn-form-custom-control-indicator-checked-box-shadow-focus) !default;
// stylelint-disable-next-line max-line-length
$custom-control-indicator-focus-border-color: var(--pgn-form-custom-control-indicator-checked-border-color-focus) !default;

// TODO switch to css variable
Expand All @@ -108,7 +111,9 @@ $custom-checkbox-indicator-icon-checked: str-replace(url("data:image/svg+
$custom-checkbox-indicator-indeterminate-bg: var(--pgn-form-custom-checkbox-indicator-indeterminate-bg) !default;
$custom-checkbox-indicator-indeterminate-color: $custom-control-indicator-checked-color !default;
$custom-checkbox-indicator-icon-indeterminate: str-replace(url("data:image/svg+xml,<svg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M21 3H3V21H21V3ZM17 13H7V11H17V13Z' fill='#{$custom-checkbox-indicator-indeterminate-color}'/></svg>"), "#", "%23") !default;
// stylelint-disable-next-line max-line-length
$custom-checkbox-indicator-indeterminate-box-shadow: var(--pgn-form-custom-checkbox-indicator-indeterminate-box-shadow) !default;
// stylelint-disable-next-line max-line-length
$custom-checkbox-indicator-indeterminate-border-color: var(--pgn-form-custom-checkbox-indicator-indeterminate-border-color) !default;

$custom-radio-indicator-border-radius: var(--pgn-form-custom-radio-indicator-border-radius) !default;
Expand Down
3 changes: 2 additions & 1 deletion src/Popover/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ $popover-arrow-width: var(--pgn-popover-arrow-width) !default;
$popover-arrow-height: var(--pgn-popover-arrow-height) !default;
$popover-arrow-color: var(--pgn-popover-arrow-color) !default;

// TODO can't use css variable due to conflict with SCSS functions, should use var(--pgn-popover-border-color) instead of #000000
// TODO can't use css variable due to conflict with SCSS functions,
// should use var(--pgn-popover-border-color) instead of #000000.
$popover-arrow-outer-color: fade-in($popover-border-color, .05) !default;

$popover-success-bg: var(--pgn-popover-success-bg) !default;
Expand Down
1 change: 1 addition & 0 deletions tokens/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async function replaceVariablesUsage(filePath, variablesMap, direction = 'scss-t
crlfDelay: Infinity,
});

// eslint-disable-next-line no-restricted-syntax
for await (const line of rl) {
let parsedLine = line;
const variables = [...parsedLine.matchAll(variableRegex)];
Expand Down

0 comments on commit de0d067

Please sign in to comment.