create.tsx 7.7 KB
Newer Older
1
2
3
4
import { MoodleThemeInterface } from './styled';

export default function createTheme(theme: MoodleThemeInterface) {
  //TODO remove !important within textfieldStyles by increasing specificity of these styles somehow
Sam Gluck's avatar
Sam Gluck committed
5
  //language=SCSS
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  const textfieldStyles = `
        && {
            border-width: 2px;
            border-color: ${theme.colour.base4};
            
            &:not(:placeholder-shown) {
                border-color: ${theme.colour.base3} !important;
            }
            
            &:hover,
            &[class*=is-hovered] {
                border-color: ${theme.colour.base3} !important;
            }
            
            &:focus,
            &[class*=is-focused] {
                border-color: ${theme.colour.primary} !important;
            }
        }
    `;

Sam Gluck's avatar
Sam Gluck committed
27
  //language=SCSS
Sam Gluck's avatar
Sam Gluck committed
28
29
30
31
32
33
  const chromeStyles = `
        && {
            background-color: ${theme.colour.base6};
        }
    `;

34
35
36
37
38
39
40
41
42
43
44
45
46
  /* The active theme definition will be available on a styled-component props
     * under the `theme.styles` property.
     *
     * @example a DIV with primary colour text
     * ```js
     * const Div = styled.div`
     *   color: ${props => props.theme.styles.colour.primary}
     * `
     * ```
     */
  return {
    ...theme,
    // zendesk garden components
Sam Gluck's avatar
Sam Gluck committed
47
48
49
    // - text fields
    'textfields.input': textfieldStyles,
    'textfields.textarea': textfieldStyles,
Sam Gluck's avatar
Sam Gluck committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    // - checkbox fields
    //language=SCSS
    'checkboxes.checkbox_view': `
        && {
            height: 35px;
        }
    `,
    //TODO style the zengarden checkbox `Message` component
    //language=SCSS
    'checkboxes.input': `
        &&&& ~ label {
            padding: 0 0 0 40px;
            height: 35px;
            position: absolute;
            display: flex;
            align-items: center;
            text-align: left;
            justify-content: flex-start;
            line-height: 1;
        }

        &&&& ~ label:before {
            content: '';
            display: block;
            position: absolute;
            height: 30px;
            width: 30px;
            background-color: white;
            border-radius: 3px;
            border: 2px solid ${theme.colour.base4};
            cursor: pointer;
            margin: 0;
            left: 0;
            top: 0;
        }

        &&&&:disabled ~ label:before {
            cursor: default;            
        }
        
        &&&&:hover ~ label:before,
        &&&& ~ label[class*=is-hover]:before {
            border: 2px solid ${theme.colour.primary};
        }
        
        &&&&:checked ~ label:before {
            border: 2px solid ${theme.colour.primary};
            background-color: ${theme.colour.primary};
        }
        
        &&&&:focus ~ label:before {
            border: 2px solid ${theme.colour.primary};
        }
        
        &&&&:active ~ label:before {
            background-color: ${theme.colour.base5};
        }
        
        &&&&:active:checked ~ label:before {
            border: 2px solid ${theme.colour.primary};
            background-color: ${theme.colour.primary};
        }
    `,
Sam Gluck's avatar
Sam Gluck committed
113
114
115
    // - chrome
    'chrome.chrome': chromeStyles,
    'chrome.body': chromeStyles,
Sam Gluck's avatar
Sam Gluck committed
116
117
118
119
120
121
    'chrome.nav': `
        && {
            background-color: ${theme.colour.primary};
        }    
    `,
    'chrome.subnav': `
Sam Gluck's avatar
Sam Gluck committed
122
123
        &&&& {
            padding: 11px 20px;
Sam Gluck's avatar
Sam Gluck committed
124
125
126
127
128
129
130
131
            background-color: ${theme.colour.primaryAlt};
        }    
    `,
    'chrome.nav_item': `
        &&&&[class*=is-current] {
            background-color: ${theme.colour.primaryAlt};
        }    
    `,
132
    // - headings
Sam Gluck's avatar
Sam Gluck committed
133
    //language=SCSS
134
    'typography.xxxl': `
Sam Gluck's avatar
Sam Gluck committed
135
136
137
138
139
140
141
        && {
            font-size: ${theme.fontSize.xxxl};
            line-height: ${theme.lineHeight.xxxl};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
Sam Gluck's avatar
Sam Gluck committed
142
    //language=SCSS
143
    'typography.xxl': `
Sam Gluck's avatar
Sam Gluck committed
144
145
146
147
148
149
150
        && {
            font-size: ${theme.fontSize.xxl};
            line-height: ${theme.lineHeight.xxl};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
Sam Gluck's avatar
Sam Gluck committed
151
    //language=SCSS
152
    'typography.xl': `
Sam Gluck's avatar
Sam Gluck committed
153
154
155
156
157
158
159
        && {
            font-size: ${theme.fontSize.xl};
            line-height: ${theme.lineHeight.xl};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
Sam Gluck's avatar
Sam Gluck committed
160
    //language=SCSS
161
    'typography.lg': `
Sam Gluck's avatar
Sam Gluck committed
162
163
164
165
166
167
168
        && {
            font-size: ${theme.fontSize.lg};
            line-height: ${theme.lineHeight.lg};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
Sam Gluck's avatar
Sam Gluck committed
169
    //language=SCSS
170
    'typography.md': `
Sam Gluck's avatar
Sam Gluck committed
171
172
173
174
175
176
177
        && {
            font-size: ${theme.fontSize.md};
            line-height: ${theme.lineHeight.md};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
178
    // - paragraph
Sam Gluck's avatar
Sam Gluck committed
179
    //language=SCSS
180
    'typography.sm': `
Sam Gluck's avatar
Sam Gluck committed
181
182
183
184
185
186
187
188
189
        && {
            font-size: ${theme.fontSize.sm};
            line-height: ${theme.lineHeight.sm};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
            margin-block-start: 1em;
            margin-block-end: 1em;
        }
    `,
190
    // - buttons
Sam Gluck's avatar
Sam Gluck committed
191
    //language=SCSS
192
    'buttons.button': `
Sam Gluck's avatar
Sam Gluck committed
193
194
        // double "&&" increases the specificity by concatenating the Button classname with itself
        &&&&,
Sam Gluck's avatar
Sam Gluck committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
        &&[class*=is-active] {
            font-weight: ${theme.fontWeight.semibold};
            background-color: ${theme.colour.primary};
            color: ${theme.colour.base6};
            border: 2px solid ${theme.colour.primary};
            
            &:hover:not(:disabled),
            &[class*=is-hovered] {
                background-color: ${theme.colour.base6};
                color: ${theme.colour.primary};
                border-color: ${theme.colour.primary};
            }

            &.secondary {
Sam Gluck's avatar
Sam Gluck committed
209
                background-color: transparent;
Sam Gluck's avatar
Sam Gluck committed
210
211
212
213
214
215
216
217
218
                color: ${theme.colour.base1};
                border: 2px solid ${theme.colour.base1};
            }
            
            &.secondary:active,
            &.secondary:hover:not(:disabled),
            &.secondary[class*=is-active],
            &.secondary[class*=is-hovered] {
                background-color: ${theme.colour.base1};
219
                color: ${theme.colour.base6};
Sam Gluck's avatar
Sam Gluck committed
220
                border-color: ${theme.colour.base1};
221
            }
Sam Gluck's avatar
Sam Gluck committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
            
            &:disabled {
                background-color: ${theme.colour.base6};
                color: ${theme.colour.primary};
                border-color: ${theme.colour.primary};
                opacity: 0.5;
                cursor: default;
            }
            
            &.secondary:disabled {
                background-color: ${theme.colour.base6};
                color: ${theme.colour.base1};
                border-color: ${theme.colour.base1};
                opacity: 0.5;
                cursor: default;
            }
        }
    `,
240
241
    // - tags
    //TODO how to style "selected" tag as per style guide? is selected === focused?
Sam Gluck's avatar
Sam Gluck committed
242
    //language=SCSS
243
    'tags.tag_view': `
Sam Gluck's avatar
Sam Gluck committed
244
        && {
Sam Gluck's avatar
Sam Gluck committed
245
            padding: 15px;
Sam Gluck's avatar
Sam Gluck committed
246
247
            background-color: ${theme.colour.base5};
            border: 1px solid ${theme.colour.base4};
Sam Gluck's avatar
Sam Gluck committed
248
            cursor: pointer;
Sam Gluck's avatar
Sam Gluck committed
249
        }
Sam Gluck's avatar
Sam Gluck committed
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
    `,
    // - pagination
    //language=SCSS
    'pagination.page': `
        &&[class*=is-current] {
            background-color: ${theme.colour.primary};
            color: white;
        }
    `,
    // - tabs
    //language=SCSS
    'tabs.tab': `
        &&&& {
            font-weight: bold;
        }
  
        &&&&[class*=is-selected] {
            color: ${theme.colour.primary};      
            border-color: ${theme.colour.primary};
        }
  
        &&&&:hover {
            color: ${theme.colour.primary};
        }
Sam Gluck's avatar
Sam Gluck committed
274
    `
275
276
  };
}