Skip to content

Commit 4764618

Browse files
authored
New avatar component (#41997)
* New avatar component * bump
1 parent a4fe099 commit 4764618

File tree

5 files changed

+373
-5
lines changed

5 files changed

+373
-5
lines changed

.bundlewatch.config.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@
2626
},
2727
{
2828
"path": "./dist/css/bootstrap.css",
29-
"maxSize": "37.5 kB"
29+
"maxSize": "38.0 kB"
3030
},
3131
{
3232
"path": "./dist/css/bootstrap.min.css",
33-
"maxSize": "36.25 kB"
33+
"maxSize": "36.75 kB"
3434
},
3535
{
3636
"path": "./dist/js/bootstrap.bundle.js",
37-
"maxSize": "67.75 kB"
37+
"maxSize": "67.5 kB"
3838
},
3939
{
4040
"path": "./dist/js/bootstrap.bundle.min.js",
4141
"maxSize": "41.0 kB"
4242
},
4343
{
4444
"path": "./dist/js/bootstrap.esm.js",
45-
"maxSize": "39.0 kB"
45+
"maxSize": "38.75 kB"
4646
},
4747
{
4848
"path": "./dist/js/bootstrap.esm.min.js",
4949
"maxSize": "24.0 kB"
5050
},
5151
{
5252
"path": "./dist/js/bootstrap.js",
53-
"maxSize": "39.75 kB"
53+
"maxSize": "39.5 kB"
5454
},
5555
{
5656
"path": "./dist/js/bootstrap.min.js",

scss/_avatar.scss

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
@use "variables" as *;
2+
@use "theme" as *;
3+
@use "mixins/border-radius" as *;
4+
5+
// scss-docs-start avatar-variables
6+
$avatar-size: 2.5rem !default;
7+
$avatar-size-xs: 1.5rem !default;
8+
$avatar-size-sm: 2rem !default;
9+
$avatar-size-lg: 3rem !default;
10+
$avatar-size-xl: 4rem !default;
11+
$avatar-border-radius: 50% !default;
12+
$avatar-border-width: 2px !default;
13+
$avatar-border-color: var(--bg-body) !default;
14+
$avatar-bg: var(--bg-2) !default;
15+
$avatar-color: var(--color-body) !default;
16+
17+
$avatar-status-size: .75rem !default;
18+
$avatar-status-border-width: 2px !default;
19+
$avatar-status-border-color: var(--bg-body) !default;
20+
21+
$avatar-stack-spacing: -.3 !default; // Percentage of avatar size (negative for overlap)
22+
// scss-docs-end avatar-variables
23+
24+
@layer components {
25+
.avatar {
26+
// scss-docs-start avatar-css-vars
27+
--avatar-border-radius: #{$avatar-border-radius};
28+
--avatar-border-width: #{$avatar-border-width};
29+
--avatar-border-color: #{$avatar-border-color};
30+
--avatar-bg: #{$avatar-bg};
31+
--avatar-color: #{$avatar-color};
32+
--avatar-status-size: #{$avatar-status-size};
33+
--avatar-status-border-width: #{$avatar-status-border-width};
34+
--avatar-status-border-color: #{$avatar-status-border-color};
35+
// scss-docs-end avatar-css-vars
36+
37+
position: relative;
38+
display: inline-flex;
39+
align-items: center;
40+
justify-content: center;
41+
width: var(--avatar-size, #{$avatar-size});
42+
height: var(--avatar-size, #{$avatar-size});
43+
font-size: calc(var(--avatar-size) * .4);
44+
font-weight: $font-weight-medium;
45+
line-height: 1;
46+
color: var(--theme-contrast, var(--avatar-color));
47+
text-transform: uppercase;
48+
vertical-align: middle;
49+
background-color: var(--theme-bg, var(--avatar-bg));
50+
@include border-radius(var(--avatar-border-radius));
51+
}
52+
53+
.avatar-subtle {
54+
color: var(--theme-text, var(--avatar-color));
55+
background-color: var(--theme-bg-subtle, var(--avatar-bg));
56+
}
57+
58+
.avatar-img {
59+
width: 100%;
60+
height: 100%;
61+
object-fit: cover;
62+
@include border-radius(inherit);
63+
}
64+
65+
.avatar-status {
66+
position: absolute;
67+
right: calc(var(--avatar-status-border-width) * -1);
68+
bottom: calc(var(--avatar-status-border-width) * -1);
69+
width: var(--avatar-status-size);
70+
height: var(--avatar-status-size);
71+
background-color: var(--gray-400);
72+
border: var(--avatar-status-border-width) solid var(--avatar-status-border-color);
73+
@include border-radius(50%);
74+
75+
&.status-online {
76+
background-color: var(--green-500);
77+
}
78+
79+
&.status-offline {
80+
background-color: var(--gray-400);
81+
@include border-radius(20%);
82+
}
83+
84+
&.status-busy {
85+
background-color: var(--red-500);
86+
@include border-radius(20%);
87+
}
88+
89+
&.status-away {
90+
background-color: var(--yellow-500);
91+
}
92+
}
93+
94+
.avatar-stack {
95+
display: inline-flex;
96+
flex-direction: row-reverse;
97+
98+
.avatar {
99+
// Stack spacing is calculated as a percentage of avatar size
100+
margin-left: calc(var(--avatar-size, #{$avatar-size}) * #{$avatar-stack-spacing});
101+
border: var(--avatar-border-width) solid var(--avatar-border-color);
102+
mask-image: none;
103+
104+
&:last-child {
105+
margin-left: 0;
106+
}
107+
108+
&:hover {
109+
z-index: 1;
110+
transform: translateY(-2px);
111+
}
112+
}
113+
}
114+
115+
.avatar-xs,
116+
.avatar-stack-xs {
117+
--avatar-size: #{$avatar-size-xs};
118+
--avatar-status-size: .625rem;
119+
}
120+
121+
.avatar-sm,
122+
.avatar-stack-sm {
123+
--avatar-size: #{$avatar-size-sm};
124+
}
125+
126+
.avatar-lg,
127+
.avatar-stack-lg {
128+
--avatar-size: #{$avatar-size-lg};
129+
--avatar-status-size: 1rem;
130+
}
131+
132+
.avatar-xl,
133+
.avatar-stack-xl {
134+
--avatar-size: #{$avatar-size-xl};
135+
--avatar-status-size: 1.25rem;
136+
}
137+
}

scss/bootstrap.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// Components
1414
@forward "accordion";
1515
@forward "alert";
16+
@forward "avatar";
1617
@forward "badge";
1718
@forward "breadcrumb";
1819
@forward "card";

site/data/sidebar.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
pages:
8686
- title: Accordion
8787
- title: Alert
88+
- title: Avatar
8889
- title: Badge
8990
- title: Breadcrumb
9091
- title: Buttons

0 commit comments

Comments
 (0)