Skip to content

Commit b3fa2a6

Browse files
authored
feat(chip): improve chip custom theme functions (#15619)
1 parent 846fbde commit b3fa2a6

File tree

1 file changed

+64
-47
lines changed

1 file changed

+64
-47
lines changed

projects/igniteui-angular/src/lib/core/styles/components/chip/_chip-theme.scss

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -106,94 +106,116 @@
106106
}
107107

108108
$theme: digest-schema($chip-schema);
109-
$meta: map.get($theme, '_meta');
109+
$variant: map.get($theme, '_meta', 'theme');
110110

111111
@if not($text-color) and $background {
112-
$text-color: text-contrast($background);
112+
$text-color: adaptive-contrast(var(--background));
113113
}
114114

115-
@if not($hover-background) and $background {
116-
$luminance: luminance($background);
115+
@if not($border-color) and $background {
116+
$border-color: var(--background);
117+
}
117118

118-
@if meta.type-of($luminance) == 'color' and $luminance + .05 < .5 {
119-
$hover-background: color.scale($background, $lightness: 14%);
120-
} @else {
121-
$hover-background: color.scale($background, $lightness: -4%);
122-
}
119+
@if not($hover-background) and $background {
120+
$hover-background: hsl(from var(--background) h s calc(l * 0.9));
123121
}
124122

125123
@if not($hover-text-color) and $hover-background {
126-
$hover-text-color: text-contrast(to-opaque($hover-background));
124+
$hover-text-color: adaptive-contrast(var(--hover-background));
127125
}
128126

129127
@if not($focus-background) and $background {
130-
$luminance: luminance($background);
128+
$focus-background: hsl(from var(--background) h s calc(l * 0.8));
129+
}
131130

132-
@if meta.type-of($luminance) == 'color' and $luminance + .05 < .5 {
133-
$focus-background: color.scale($background, $lightness: 22%);
134-
} @else {
135-
$focus-background: color.scale($background, $lightness: -8%);
131+
@if $variant == 'fluent' {
132+
@if not($focus-background) and $selected-background {
133+
$focus-background: var(--selected-background);
136134
}
137135
}
138136

139137
@if not($focus-text-color) and $focus-background {
140-
$focus-text-color: text-contrast(to-opaque($focus-background));
138+
$focus-text-color: adaptive-contrast(var(--focus-background));
141139
}
142140

143-
@if not($selected-background) and $background {
144-
$luminance: luminance($background);
145-
146-
@if meta.type-of($luminance) == 'color' and $luminance + .05 < .5 {
147-
$selected-background: color.scale($background, $lightness: 22%);
148-
} @else {
149-
$selected-background: color.scale($background, $lightness: -8%);
141+
@if $variant != 'indigo' and $variant != 'fluent' {
142+
@if not($selected-background) and $background {
143+
$selected-background: var(--background);
144+
}
145+
} @else {
146+
@if not($selected-background) and $background {
147+
$selected-background: hsl(from var(--background) h s calc(l * 1.1));
150148
}
151149
}
152150

153151
@if not($selected-text-color) and $selected-background {
154-
$selected-text-color: text-contrast(to-opaque($selected-background));
152+
$selected-text-color: adaptive-contrast(var(--selected-background));
155153
}
156154

157-
@if not($hover-selected-background) and $hover-background {
158-
$hover-selected-background: $hover-background;
155+
@if not($hover-selected-background) and $selected-background {
156+
$hover-selected-background: hsl(from var(--selected-background) h s calc(l * 0.9));
159157
}
160158

161159
@if not($hover-selected-text-color) and $hover-selected-background {
162-
$hover-selected-text-color: text-contrast(to-opaque($hover-selected-background));
160+
$hover-selected-text-color: adaptive-contrast(var(--hover-selected-background));
163161
}
164162

165-
@if not($focus-selected-background) and $selected-background {
166-
$luminance: luminance($selected-background);
167-
168-
@if meta.type-of($luminance) == 'color' and $luminance + .05 < .5 {
169-
$focus-selected-background: color.scale($background, $lightness: 32%);
170-
} @else {
171-
$focus-selected-background: color.scale($background, $lightness: -16%);
163+
@if $variant != 'indigo' {
164+
@if not($focus-selected-background) and $selected-background {
165+
$focus-selected-background: hsl(from var(--selected-background) h s calc(l * 0.8));
166+
}
167+
} @else {
168+
@if not($focus-selected-background) and $selected-background {
169+
$focus-selected-background: var(--selected-background);
172170
}
173171
}
174172

175173
@if not($focus-selected-text-color) and $focus-selected-background {
176-
$focus-selected-text-color: text-contrast(to-opaque($focus-selected-background));
174+
$focus-selected-text-color: adaptive-contrast(var(--focus-selected-background));
177175
}
178176

179177
@if not($hover-border-color) and $border-color {
180-
$hover-border-color: $border-color;
178+
$hover-border-color: var(--border-color);
181179
}
182180

183181
@if not($focus-border-color) and $border-color {
184-
$focus-border-color: $border-color;
182+
$focus-border-color: var(--border-color);
185183
}
186184

187185
@if not($selected-border-color) and $border-color {
188-
$selected-border-color: $border-color;
186+
$selected-border-color: var(--border-color);
189187
}
190188

191189
@if not($hover-selected-border-color) and $border-color {
192-
$hover-selected-border-color: $border-color;
190+
$hover-selected-border-color: var(--border-color);
193191
}
194192

195193
@if not($focus-selected-border-color) and $border-color {
196-
$focus-selected-border-color: $border-color;
194+
$focus-selected-border-color: var(--border-color);
195+
}
196+
197+
@if $variant == 'indigo' {
198+
@if not($selected-border-color) and $selected-background {
199+
$selected-border-color: var(--selected-background);
200+
}
201+
202+
@if not($hover-selected-border-color) and $hover-selected-background {
203+
$hover-selected-border-color: var(--hover-selected-background);
204+
}
205+
206+
@if not($focus-selected-border-color) and $focus-selected-background {
207+
$focus-selected-border-color: var(--focus-selected-background);
208+
}
209+
}
210+
211+
@if $variant == 'bootstrap' or $variant == 'indigo' {
212+
@if not($focus-outline-color) and $focus-background {
213+
$focus-outline-color: hsla(from var(--focus-background) h s l / 0.4);
214+
}
215+
216+
@if not($focus-selected-outline-color) and $focus-selected-background {
217+
$focus-selected-outline-color: hsla(from var(--focus-selected-background) h s l / 0.4);
218+
}
197219
}
198220

199221
@if not($ghost-shadow) {
@@ -240,11 +262,6 @@
240262
remove-icon-color-focus: $remove-icon-color-focus,
241263
focus-selected-outline-color: $focus-selected-outline-color,
242264
focus-outline-color: $focus-outline-color,
243-
theme: map.get($schema, '_meta', 'theme'),
244-
_meta: map.merge(if($meta, $meta, ()), (
245-
variant: map.get($schema, '_meta', 'theme'),
246-
theme-variant: map.get($schema, '_meta', 'variant')
247-
)),
248265
size: $size,
249266
));
250267
}
@@ -256,8 +273,8 @@
256273
@include css-vars($theme);
257274
$chip-max-width: 32ch;
258275

259-
$variant: map.get($theme, '_meta', 'variant');
260-
$theme-variant: map.get($theme, '_meta', 'theme-variant');
276+
$variant: map.get($theme, '_meta', 'theme');
277+
$theme-variant: map.get($theme, '_meta', 'variant');
261278

262279
$chip-padding: (
263280
comfortable: rem(if($variant != 'indigo', 12px, 7px)),

0 commit comments

Comments
 (0)