Skip to content

Commit 9828d0d

Browse files
committed
refactor(badge, button): use spacing for margin and padding
1 parent b717f37 commit 9828d0d

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

projects/igniteui-angular/src/lib/core/styles/base/_variables.scss

+7
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,10 @@ $enhanced-accessibility: false !default;
131131

132132
/// Stores a list of dropped component themes.
133133
$dropped-themes: () !default;
134+
135+
/// A map that stores the default spacing values.
136+
$spacing: (
137+
comfortable: 8px,
138+
cosy: 4px,
139+
compact: 2px
140+
);

projects/igniteui-angular/src/lib/core/styles/base/utilities/_functions.scss

+19
Original file line numberDiff line numberDiff line change
@@ -961,3 +961,22 @@ $p-test: palette(#fff, #000);
961961

962962
@return $used;
963963
}
964+
965+
/// Returns a value based on the global spacing config for the specified display density.
966+
/// @access private
967+
@function spacing($value, $density: 'comfortable') {
968+
$space: map.get($spacing, $density);
969+
$ratio: 1;
970+
971+
@if math.compatible($value, $space) {
972+
$ratio: math.div($value, $space);
973+
} @else {
974+
@error 'Spacing must be specified in pixel values.';
975+
}
976+
977+
@if ($ratio == 1) {
978+
@return var(--igx-spacing-#{$density});
979+
} @else {
980+
@return calc(var(--igx-spacing-#{$density}) * #{$ratio});
981+
}
982+
}

projects/igniteui-angular/src/lib/core/styles/components/badge/_badge-theme.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107

108108
$badge-icon-font-size: rem(12px);
109109

110-
$badge-value-padding: rem(4px);
110+
$badge-value-padding: spacing(4px);
111111
$border-type: solid;
112112

113113
%igx-badge-display {

projects/igniteui-angular/src/lib/core/styles/components/button/_button-theme.scss

+24-24
Original file line numberDiff line numberDiff line change
@@ -264,39 +264,39 @@
264264
$button-icon-padding: 0;
265265

266266
$button-padding-material: (
267-
comfortable: rem(9px, 16px) rem(16px, 16px),
268-
cosy: rem(6px, 16px) rem(16px, 16px),
269-
compact: rem(3px, 16px) rem(16px, 16px)
267+
comfortable: spacing(9px, 'comfortable') spacing(16px, 'comfortable'),
268+
cosy: spacing(6px, 'cosy') spacing(16px, 'cosy'),
269+
compact: spacing(3px, 'compact') spacing(16px, 'compact')
270270
);
271271

272272
$outlined-button-padding-material: (
273-
comfortable: rem(7px, 16px) rem(14px, 16px),
274-
cosy: rem(4px, 16px) rem(14px, 16px),
275-
compact: rem(1px, 16px) rem(14px, 16px)
273+
comfortable: spacing(7px, 'comfortable') spacing(14px, 'comfortable'),
274+
cosy: spacing(4px, 'cosy') spacing(14px, 'cosy'),
275+
compact: spacing(1px, 'compact') spacing(14px, 'compact')
276276
);
277277

278278
$button-padding-fluent: (
279-
comfortable: 0 rem(16px, 16px),
280-
cosy: 0 rem(16px, 16px),
281-
compact: 0 rem(16px, 16px)
279+
comfortable: 0 spacing(16px, 'comfortable'),
280+
cosy: 0 spacing(16px, 'cosy'),
281+
compact: 0 spacing(16px, 'compact')
282282
);
283283

284284
$button-padding-bootstrap: (
285-
comfortable: rem(6px, 16px) rem(12px, 16px),
286-
cosy: rem(4px, 16px) rem(10px, 16px),
287-
compact: rem(2px, 16px) rem(8px, 16px)
285+
comfortable: spacing(6px, 'comfortable') spacing(12px, 'comfortable'),
286+
cosy: spacing(4px, 'cosy') spacing(10px, 'cosy'),
287+
compact: spacing(2px, 'compact') spacing(8px, 'compact')
288288
);
289289

290290
$button-padding-indigo: (
291-
comfortable: rem(3px, 16px) rem(12px, 16px),
292-
cosy: rem(2px, 16px) rem(12px, 16px),
293-
compact: rem(1px, 16px) rem(8px, 16px)
291+
comfortable: spacing(3px, 'comfortable') spacing(12px, 'comfortable'),
292+
cosy: spacing(2px, 'cosy') spacing(12px, 'cosy'),
293+
compact: spacing(1px, 'compact') spacing(8px, 'compact')
294294
);
295295

296296
$outlined-button-padding-indigo: (
297-
comfortable: rem(6px, 16px) rem(14px, 16px),
298-
cosy: rem(4px, 16px) rem(10px, 16px),
299-
compact: rem(2px, 16px) rem(6px, 16px)
297+
comfortable: spacing(6px, 'comfortable') spacing(14px, 'comfortable'),
298+
cosy: spacing(4px, 'cosy') spacing(10px, 'cosy'),
299+
compact: spacing(2px, 'cosy') spacing(6px, 'cosy')
300300
);
301301

302302
$icon-button-width-material: (
@@ -376,9 +376,9 @@
376376
), $variant);
377377

378378
$button-floating-padding: (
379-
comfortable: rem(8px) rem(14px),
380-
cosy: rem(4px) rem(10px),
381-
compact: 0 rem(6px)
379+
comfortable: spacing(8px, 'comfortable') spacing(14px, 'comfortable'),
380+
cosy: spacing(4px, 'cosy') spacing(10px, 'cosy'),
381+
compact: 0 spacing(6px, 'compact')
382382
);
383383

384384
$button-floating-size: (
@@ -394,9 +394,9 @@
394394
);
395395

396396
$icon-in-button-margin: (
397-
comfortable: rem(12px),
398-
cosy: rem(8px),
399-
compact: rem(4px)
397+
comfortable: spacing(12px, 'comfortable'),
398+
cosy: spacing(8px, 'cosy'),
399+
compact: spacing(4px, 'compact')
400400
);
401401

402402
$icon-sizes: map.get((

projects/igniteui-angular/src/lib/core/styles/themes/_index.scss

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
@use 'sass:list';
77
@use 'sass:string';
8+
@use 'sass:map';
89
@use '../base' as *;
910
@use 'schemas' as *;
1011
@use 'palettes' as *;
@@ -70,6 +71,18 @@
7071

7172
$theme-palette: $palette !global;
7273

74+
:root {
75+
--igx-spacing-comfortable: #{rem(map.get($spacing, 'comfortable'))};
76+
--igx-spacing-cosy: #{rem(map.get($spacing, 'cosy'))};
77+
--igx-spacing-compact: #{rem(map.get($spacing, 'compact'))};
78+
79+
@if $wc {
80+
--igc-spacing-large: var(--igx-spacing-comfortable);
81+
--igc-spacing-medium: var(--igx-spacing-cosy);
82+
--igc-spacing-small: var(--igx-spacing-compact);
83+
}
84+
}
85+
7386
@if list.length($exclude) > 0 {
7487
$excluded: is-component($exclude);
7588
}

0 commit comments

Comments
 (0)