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