create.tsx 7.82 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
    //language=SCSS
Sam Gluck's avatar
Sam Gluck committed
117
118
119
120
121
    'chrome.nav': `
        && {
            background-color: ${theme.colour.primary};
        }    
    `,
Sam Gluck's avatar
Sam Gluck committed
122
    //language=SCSS
Sam Gluck's avatar
Sam Gluck committed
123
    'chrome.subnav': `
Sam Gluck's avatar
Sam Gluck committed
124
125
        &&&& {
            padding: 11px 20px;
Sam Gluck's avatar
Sam Gluck committed
126
127
128
            background-color: ${theme.colour.primaryAlt};
        }    
    `,
Sam Gluck's avatar
Sam Gluck committed
129
    //language=SCSS
Sam Gluck's avatar
Sam Gluck committed
130
131
132
133
134
    'chrome.nav_item': `
        &&&&[class*=is-current] {
            background-color: ${theme.colour.primaryAlt};
        }    
    `,
135
    // - headings
Sam Gluck's avatar
Sam Gluck committed
136
    //language=SCSS
137
    'typography.xxxl': `
Sam Gluck's avatar
Sam Gluck committed
138
139
140
141
142
143
144
        && {
            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
145
    //language=SCSS
146
    'typography.xxl': `
Sam Gluck's avatar
Sam Gluck committed
147
148
149
150
151
152
153
        && {
            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
154
    //language=SCSS
155
    'typography.xl': `
Sam Gluck's avatar
Sam Gluck committed
156
157
158
159
160
161
162
        && {
            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
163
    //language=SCSS
164
    'typography.lg': `
Sam Gluck's avatar
Sam Gluck committed
165
        && {
166
167
            margin-block-start: .65em;
            margin-block-end: .65em;
Sam Gluck's avatar
Sam Gluck committed
168
169
170
171
172
173
            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
174
    //language=SCSS
175
    'typography.md': `
Sam Gluck's avatar
Sam Gluck committed
176
177
178
179
180
181
182
        && {
            font-size: ${theme.fontSize.md};
            line-height: ${theme.lineHeight.md};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
183
    // - paragraph
Sam Gluck's avatar
Sam Gluck committed
184
    //language=SCSS
185
    'typography.sm': `
Sam Gluck's avatar
Sam Gluck committed
186
187
188
189
190
191
192
193
194
        && {
            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;
        }
    `,
195
    // - buttons
Sam Gluck's avatar
Sam Gluck committed
196
    //language=SCSS
197
    'buttons.button': `
Sam Gluck's avatar
Sam Gluck committed
198
199
        // double "&&" increases the specificity by concatenating the Button classname with itself
        &&&&,
Sam Gluck's avatar
Sam Gluck committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
        &&[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
214
                background-color: transparent;
Sam Gluck's avatar
Sam Gluck committed
215
216
217
218
219
220
221
222
223
                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};
224
                color: ${theme.colour.base6};
Sam Gluck's avatar
Sam Gluck committed
225
                border-color: ${theme.colour.base1};
226
            }
Sam Gluck's avatar
Sam Gluck committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
            
            &: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;
            }
        }
    `,
245
    // - tags
Sam Gluck's avatar
Sam Gluck committed
246
    //language=SCSS
247
    'tags.tag_view': `
Sam Gluck's avatar
Sam Gluck committed
248
        && {
249
            min-height: 45px;
Sam Gluck's avatar
Sam Gluck committed
250
            padding: 15px;
Sam Gluck's avatar
Sam Gluck committed
251
            box-shadow: 0 0 0 2px transparent;
Sam Gluck's avatar
Sam Gluck committed
252
253
            background-color: ${theme.colour.base5};
            border: 1px solid ${theme.colour.base4};
Sam Gluck's avatar
Sam Gluck committed
254
            cursor: pointer;
Sam Gluck's avatar
Sam Gluck committed
255
        }
Sam Gluck's avatar
Sam Gluck committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    `,
    // - 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
280
    `
281
282
  };
}