浏览代码

refactor(avatar) use jss instead of scss (#11037)

master
Shahab 3 年前
父节点
当前提交
c25fb702c2
没有帐户链接到提交者的电子邮件

+ 0
- 50
css/_avatar.scss 查看文件

@@ -1,50 +0,0 @@
1
-.avatar {
2
-    background-color: #AAA;
3
-    border-radius: 50%;
4
-    color: rgba(255, 255, 255, 1);
5
-    font-weight: 100;
6
-    object-fit: cover;
7
-
8
-    &.avatar-small {
9
-        height: 28px !important;
10
-        width: 28px !important;
11
-    }
12
-
13
-    &.avatar-xsmall {
14
-        height: 16px !important;
15
-        width: 16px !important;
16
-    }
17
-
18
-    .jitsi-icon {
19
-        transform: translateY(50%);
20
-    }
21
-}
22
-
23
-.avatar-svg {
24
-    height: 100%;
25
-    width: 100%;
26
-}
27
-
28
-.avatar-badge {
29
-    position: relative;
30
-
31
-    &-available::after {
32
-        @include avatarBadge;
33
-        background-color: $presence-available;
34
-    }
35
-
36
-    &-away::after {
37
-        @include avatarBadge;
38
-        background-color: $presence-away;
39
-    }
40
-
41
-    &-busy::after {
42
-        @include avatarBadge;
43
-        background-color: $presence-busy;
44
-    }
45
-
46
-    &-idle::after {
47
-        @include avatarBadge;
48
-        background-color: $presence-idle;
49
-    }
50
-}

+ 0
- 13
css/_mixins.scss 查看文件

@@ -193,16 +193,3 @@
193 193
 @mixin transparentBg($color, $alpha) {
194 194
     background-color: rgba(red($color), green($color), blue($color), $alpha);
195 195
 }
196
-
197
-/**
198
- * Avatar status badge mixin
199
- */
200
-@mixin avatarBadge {
201
-    border-radius: 50%;
202
-    content: '';
203
-    display: block;
204
-    height: 35%;
205
-    position: absolute;
206
-    bottom: 0;
207
-    width: 35%;
208
-}

+ 0
- 4
css/_variables.scss 查看文件

@@ -28,10 +28,6 @@ $defaultSemiDarkColor: #ACACAC;
28 28
 $defaultDarkColor: #2b3d5c;
29 29
 $defaultWarningColor: rgb(215, 121, 118);
30 30
 $participantsPaneBgColor: #141414;
31
-$presence-available: rgb(110, 176, 5);
32
-$presence-away: rgb(250, 201, 20);
33
-$presence-busy: rgb(233, 0, 27);
34
-$presence-idle: rgb(172, 172, 172);
35 31
 
36 32
 /**
37 33
  * Toolbar

+ 0
- 1
css/main.scss 查看文件

@@ -82,7 +82,6 @@ $flagsImagePath: "../images/";
82 82
 @import 'navigate_section_list';
83 83
 @import 'third-party-branding/google';
84 84
 @import 'third-party-branding/microsoft';
85
-@import 'avatar';
86 85
 @import 'promotional-footer';
87 86
 @import 'chrome-extension-banner';
88 87
 @import 'settings-button';

+ 5
- 4
react/features/base/avatar/components/native/styles.js 查看文件

@@ -3,6 +3,7 @@
3 3
 import { StyleSheet } from 'react-native';
4 4
 
5 5
 import { ColorPalette } from '../../../styles';
6
+import { PRESENCE_AVAILABLE_COLOR, PRESENCE_AWAY_COLOR, PRESENCE_BUSY_COLOR, PRESENCE_IDLE_COLOR } from '../styles';
6 7
 
7 8
 const DEFAULT_SIZE = 65;
8 9
 
@@ -34,16 +35,16 @@ export default {
34 35
 
35 36
         switch (status) {
36 37
         case 'available':
37
-            color = 'rgb(110, 176, 5)';
38
+            color = PRESENCE_AVAILABLE_COLOR;
38 39
             break;
39 40
         case 'away':
40
-            color = 'rgb(250, 201, 20)';
41
+            color = PRESENCE_AWAY_COLOR;
41 42
             break;
42 43
         case 'busy':
43
-            color = 'rgb(233, 0, 27)';
44
+            color = PRESENCE_BUSY_COLOR;
44 45
             break;
45 46
         case 'idle':
46
-            color = 'rgb(172, 172, 172)';
47
+            color = PRESENCE_IDLE_COLOR;
47 48
             break;
48 49
         }
49 50
 

+ 5
- 0
react/features/base/avatar/components/styles.js 查看文件

@@ -0,0 +1,5 @@
1
+// Colors for avatar status badge
2
+export const PRESENCE_AVAILABLE_COLOR = 'rgb(110, 176, 5)';
3
+export const PRESENCE_AWAY_COLOR = 'rgb(250, 201, 20)';
4
+export const PRESENCE_BUSY_COLOR = 'rgb(233, 0, 27)';
5
+export const PRESENCE_IDLE_COLOR = 'rgb(172, 172, 172)';

+ 81
- 5
react/features/base/avatar/components/web/StatelessAvatar.js 查看文件

@@ -1,12 +1,20 @@
1 1
 // @flow
2 2
 
3
+import { withStyles } from '@material-ui/core/styles';
4
+import clsx from 'clsx';
3 5
 import React from 'react';
4 6
 
5 7
 import { Icon } from '../../../icons';
6 8
 import AbstractStatelessAvatar, { type Props as AbstractProps } from '../AbstractStatelessAvatar';
9
+import { PRESENCE_AVAILABLE_COLOR, PRESENCE_AWAY_COLOR, PRESENCE_BUSY_COLOR, PRESENCE_IDLE_COLOR } from '../styles';
7 10
 
8 11
 type Props = AbstractProps & {
9 12
 
13
+    /**
14
+     * An object containing the CSS classes.
15
+     */
16
+    classes: Object,
17
+
10 18
     /**
11 19
      * External class name passed through props.
12 20
      */
@@ -38,11 +46,77 @@ type Props = AbstractProps & {
38 46
     useCORS?: ?boolean
39 47
 };
40 48
 
49
+/**
50
+ * Creates the styles for the component.
51
+ *
52
+ * @returns {Object}
53
+ */
54
+const styles = () => {
55
+    return {
56
+        avatar: {
57
+            backgroundColor: '#AAA',
58
+            borderRadius: '50%',
59
+            color: 'rgba(255, 255, 255, 1)',
60
+            fontWeight: '100',
61
+            objectFit: 'cover',
62
+
63
+            '&.avatar-small': {
64
+                height: '28px !important',
65
+                width: '28px !important'
66
+            },
67
+
68
+            '&.avatar-xsmall': {
69
+                height: '16px !important',
70
+                width: '16px !important'
71
+            },
72
+
73
+            '& .jitsi-icon': {
74
+                transform: 'translateY(50%)'
75
+            },
76
+
77
+            '& .avatar-svg': {
78
+                height: '100%',
79
+                width: '100%'
80
+            }
81
+        },
82
+
83
+        badge: {
84
+            position: 'relative',
85
+
86
+            '&.avatar-badge:after': {
87
+                borderRadius: '50%',
88
+                content: '""',
89
+                display: 'block',
90
+                height: '35%',
91
+                position: 'absolute',
92
+                bottom: 0,
93
+                width: '35%'
94
+            },
95
+
96
+            '&.avatar-badge-available:after': {
97
+                backgroundColor: PRESENCE_AVAILABLE_COLOR
98
+            },
99
+
100
+            '&.avatar-badge-away:after': {
101
+                backgroundColor: PRESENCE_AWAY_COLOR
102
+            },
103
+
104
+            '&.avatar-badge-busy:after': {
105
+                backgroundColor: PRESENCE_BUSY_COLOR
106
+            },
107
+
108
+            '&.avatar-badge-idle:after': {
109
+                backgroundColor: PRESENCE_IDLE_COLOR
110
+            }
111
+        }
112
+    };
113
+};
114
+
41 115
 /**
42 116
  * Implements a stateless avatar component that renders an avatar purely from what gets passed through
43 117
  * props.
44 118
  */
45
-export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
119
+class StatelessAvatar extends AbstractStatelessAvatar<Props> {
46 120
 
47 121
     /**
48 122
      * Instantiates a new {@code Component}.
@@ -66,7 +140,7 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
66 140
         if (this._isIcon(url)) {
67 141
             return (
68 142
                 <div
69
-                    className = { `${this._getAvatarClassName()} ${this._getBadgeClassName()}` }
143
+                    className = { clsx(this._getAvatarClassName(), this._getBadgeClassName()) }
70 144
                     data-testid = { this.props.testId }
71 145
                     id = { this.props.id }
72 146
                     style = { this._getAvatarStyle(this.props.color) }>
@@ -96,7 +170,7 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
96 170
         if (initials) {
97 171
             return (
98 172
                 <div
99
-                    className = { `${this._getAvatarClassName()} ${this._getBadgeClassName()}` }
173
+                    className = { clsx(this._getAvatarClassName(), this._getBadgeClassName()) }
100 174
                     data-testid = { this.props.testId }
101 175
                     id = { this.props.id }
102 176
                     style = { this._getAvatarStyle(this.props.color) }>
@@ -157,7 +231,7 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
157 231
      * @returns {string}
158 232
      */
159 233
     _getAvatarClassName(additional) {
160
-        return `avatar ${additional || ''} ${this.props.className || ''}`;
234
+        return clsx('avatar', additional, this.props.className, this.props.classes.avatar);
161 235
     }
162 236
 
163 237
     /**
@@ -169,7 +243,7 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
169 243
         const { status } = this.props;
170 244
 
171 245
         if (status) {
172
-            return `avatar-badge avatar-badge-${status}`;
246
+            return clsx('avatar-badge', `avatar-badge-${status}`, this.props.classes.badge);
173 247
         }
174 248
 
175 249
         return '';
@@ -192,3 +266,5 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
192 266
         }
193 267
     }
194 268
 }
269
+
270
+export default withStyles(styles)(StatelessAvatar);

正在加载...
取消
保存