create.tsx 4.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { MoodleThemeInterface } from './styled';

export default function createTheme(theme: MoodleThemeInterface) {
  //TODO remove !important within textfieldStyles by increasing specificity of these styles somehow
  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
26
27
28
29
30
31
  const chromeStyles = `
        && {
            background-color: ${theme.colour.base6};
        }
    `;

32
33
34
35
36
37
38
39
40
41
42
43
44
  /* 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
45
46
47
48
49
50
    // - text fields
    'textfields.input': textfieldStyles,
    'textfields.textarea': textfieldStyles,
    // - chrome
    'chrome.chrome': chromeStyles,
    'chrome.body': chromeStyles,
51
52
    // - headings
    'typography.xxxl': `
Sam Gluck's avatar
Sam Gluck committed
53
54
55
56
57
58
59
        && {
            font-size: ${theme.fontSize.xxxl};
            line-height: ${theme.lineHeight.xxxl};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
60
    'typography.xxl': `
Sam Gluck's avatar
Sam Gluck committed
61
62
63
64
65
66
67
        && {
            font-size: ${theme.fontSize.xxl};
            line-height: ${theme.lineHeight.xxl};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
68
    'typography.xl': `
Sam Gluck's avatar
Sam Gluck committed
69
70
71
72
73
74
75
        && {
            font-size: ${theme.fontSize.xl};
            line-height: ${theme.lineHeight.xl};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
76
    'typography.lg': `
Sam Gluck's avatar
Sam Gluck committed
77
78
79
80
81
82
83
        && {
            font-size: ${theme.fontSize.lg};
            line-height: ${theme.lineHeight.lg};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
84
    'typography.md': `
Sam Gluck's avatar
Sam Gluck committed
85
86
87
88
89
90
91
        && {
            font-size: ${theme.fontSize.md};
            line-height: ${theme.lineHeight.md};
            font-weight: ${theme.fontWeight.bold};
            letter-spacing: 0;
        }
    `,
92
93
    // - paragraph
    'typography.sm': `
Sam Gluck's avatar
Sam Gluck committed
94
95
96
97
98
99
100
101
102
        && {
            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;
        }
    `,
103
104
    // - buttons
    'buttons.button': `
Sam Gluck's avatar
Sam Gluck committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
        &&,
        &&[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 {
                background-color: ${theme.colour.base6};
                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};
130
                color: ${theme.colour.base6};
Sam Gluck's avatar
Sam Gluck committed
131
                border-color: ${theme.colour.base1};
132
            }
Sam Gluck's avatar
Sam Gluck committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
            
            &: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;
            }
        }
    `,
151
152
153
    // - tags
    //TODO how to style "selected" tag as per style guide? is selected === focused?
    'tags.tag_view': `
Sam Gluck's avatar
Sam Gluck committed
154
155
156
157
158
        && {
            background-color: ${theme.colour.base5};
            border: 1px solid ${theme.colour.base4};
        }
    `
159
160
  };
}