).toJSON()).toMatchSnapshot();
43 | });
44 |
45 | test('Creates an opaque color object from hue, saturation and value (HSV) values.', () => {
46 | const Div = styled.div`
47 | hsv1: hsv(90, 100%, 50%);
48 | hsv2: hsv(@h, @s, @v);
49 |
50 | hsva1: hsva(90, 100%, 50%, 0.5);
51 | hsva2: hsva(@h, @s, @v, @a);
52 | `;
53 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
54 | });
55 |
56 |
57 | test('Extracts the hue channel of a color object in the HSL color space.', () => {
58 | const Div = styled.div`
59 | hue: hue(hsl(90, 100%, 50%));
60 | hue: hue(#80ff00);
61 | hue: hue(@color);
62 | hue: hue(@color2);
63 | `;
64 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
65 | });
66 |
67 | test('Extracts the saturation channel of a color object in the HSL color space.', () => {
68 | const Div = styled.div`
69 | saturation: saturation(hsl(90, 100%, 50%));
70 | saturation: saturation(#80ff00);
71 | saturation: saturation(@color);
72 | saturation: saturation(@color2);
73 |
74 | saturation: saturation(hsl(90, 50%, 50%));
75 | `;
76 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
77 | });
78 |
79 | test('Extracts the lightness channel of a color object in the HSL color space.', () => {
80 | const Div = styled.div`
81 | lightness: lightness(hsl(90, 100%, 50%));
82 | lightness: lightness(#80ff00);
83 | lightness: lightness(@color);
84 | lightness: lightness(@color2);
85 |
86 | lightness: lightness(hsl(90, 50%, 50%));
87 | `;
88 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
89 | });
90 |
91 | test('Extract and reconstruct an hsl color.', () => {
92 | const Div = styled.div`
93 | @col: hsl(90, 50%, 50%);
94 | col-before: @col;
95 | col-after: hsl(hue(@col), saturation(@col), lightness(@col));
96 | `;
97 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
98 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
99 | });
100 |
101 |
102 | test('Extracts the hue channel of a color object in the HSV color space.', () => {
103 | const Div = styled.div`
104 | hsvhue: hsvhue(hsv(90, 100%, 50%));
105 | hsvhue: hsvhue(#80ff00);
106 | hsvhue: hsvhue(@color);
107 | hsvhue: hsvhue(@color2);
108 | `;
109 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
110 | });
111 |
112 | test('Extracts the saturation channel of a color object in the HSV color space.', () => {
113 | const Div = styled.div`
114 | hsvsaturation: hsvsaturation(hsv(90, 100%, 50%));
115 | hsvsaturation: hsvsaturation(#80ff00);
116 | hsvsaturation: hsvsaturation(@color);
117 | hsvsaturation: hsvsaturation(@color2);
118 |
119 | hsvsaturation: hsvsaturation(hsv(90, 50%, 50%));
120 | `;
121 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
122 | });
123 |
124 | test('Extracts the value channel of a color object in the HSV color space.', () => {
125 | const Div = styled.div`
126 | hsvvalue: hsvvalue(hsv(90, 100%, 50%));
127 | hsvvalue: hsvvalue(#408000);
128 | hsvvalue: hsvvalue(@color);
129 | hsvvalue: hsvvalue(@color2);
130 |
131 | hsvvalue: hsvvalue(hsv(90, 50%, 50%));
132 | `;
133 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
134 | });
135 |
136 | test('Extract and reconstruct an hsv color.', () => {
137 | const Div = styled.div`
138 | @col: hsv(90, 50%, 50%);
139 | col-before: @col;
140 | col-after: hsv(hsvhue(@col), hsvsaturation(@col), hsvvalue(@col));
141 | `;
142 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
143 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
144 | });
145 |
146 |
147 | test('Extracts the red channel of a color object.', () => {
148 | const Div = styled.div`
149 | red: red(rgb(10, 20, 30));
150 | red: red(rgb(@r, @g, @b));
151 | red: red(@color);
152 | `;
153 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
154 | });
155 |
156 | test('Extracts the green channel of a color object.', () => {
157 | const Div = styled.div`
158 | green: green(rgb(10, 20, 30));
159 | green: green(rgb(@r, @g, @b));
160 | green: green(@color);
161 | `;
162 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
163 | });
164 |
165 | test('Extracts the blue channel of a color object.', () => {
166 | const Div = styled.div`
167 | blue: blue(rgb(10, 20, 30));
168 | blue: blue(rgb(@r, @g, @b));
169 | blue: blue(@color);
170 | `;
171 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
172 | });
173 |
174 | test('Extracts the alpha channel of a color object.', () => {
175 | const Div = styled.div`
176 | alpha: alpha(rgba(10, 20, 30, 0.5));
177 | alpha: alpha(rgba(@r, @g, @b, 0.5));
178 | alpha: alpha(@color);
179 | `;
180 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
181 | });
182 |
183 |
184 | test('Calculates the luma (perceptual brightness) of a color object.', () => {
185 | const Div = styled.div`
186 | luma: luma(rgb(100, 200, 30));
187 | luma: luma(@color);
188 | `;
189 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
190 | });
191 |
192 | test('Calculates the value of the luma without gamma correction.', () => {
193 | const Div = styled.div`
194 | luminance: luminance(rgb(100, 200, 30));
195 | luminance: luminance(@color);
196 |
197 | luminance: luminance(rgba(100, 200, 30, 0.5));
198 | `;
199 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
200 | });
201 |
202 |
203 | test('Increase the saturation of a color in the HSL color space by an absolute amount.', () => {
204 | const Div = styled.div`
205 | saturate: saturate(hsl(90, 80%, 50%), 20%);
206 | saturate: saturate(@color, 20%);
207 | saturate: saturate(@color, @p);
208 |
209 | saturatea: saturate(hsla(90, 80%, 50%, 0.5), 20%);
210 | saturatea: saturate(@colora, 20%);
211 | saturatea: saturate(@colora, @p);
212 | `;
213 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
214 | });
215 | test('Decrease the saturation of a color in the HSL color space by an absolute amount.', () => {
216 | const Div = styled.div`
217 | desaturate: desaturate(hsl(90, 80%, 50%), 20%);
218 | desaturate: desaturate(@color, 20%);
219 | desaturate: desaturate(@color, @p);
220 |
221 | desaturatea: desaturate(hsla(90, 80%, 50%, 0.5), 20%);
222 | desaturatea: desaturate(@colora, 20%);
223 | desaturatea: desaturate(@colora, @p);
224 | `;
225 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
226 | });
227 |
228 |
229 | test('Increase the lightness of a color in the HSL color space by an absolute amount.', () => {
230 | const Div = styled.div`
231 | lighten: lighten(hsl(90, 80%, 50%), 20%);
232 | lighten: lighten(@color, 20%);
233 | lighten: lighten(@color, @p);
234 |
235 | lightena: lighten(hsla(90, 80%, 50%, 0.5), 20%);
236 | lightena: lighten(@colora, 20%);
237 | lightena: lighten(@colora, @p);
238 | `;
239 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
240 | });
241 | test('Decrease the lightness of a color in the HSL color space by an absolute amount.', () => {
242 | const Div = styled.div`
243 | darken: darken(hsl(90, 80%, 50%), 20%);
244 | darken: darken(@color, 20%);
245 | darken: darken(@color, @p);
246 |
247 | darkena: darken(hsla(90, 80%, 50%, 0.5), 20%);
248 | darkena: darken(@colora, 20%);
249 | darkena: darken(@colora, @p);
250 | `;
251 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
252 | });
253 |
254 |
255 | test('Decrease the transparency (or increase the opacity) of a color, making it more opaque. Has no effect on opaque colors.', () => {
256 | const Div = styled.div`
257 | fadein: fadein(hsla(90, 90%, 50%, 0.5), 10%);
258 | fadein: fadein(@color, 10%);
259 | fadein: fadein(@color, @p);
260 |
261 | fadein: fadein(hsla(90, 90%, 50%, 0.5), 10%, relative);
262 | fadein: fadein(@color, 10%, relative);
263 | fadein: fadein(@color, @p, @r);
264 |
265 | fadein: fadein(@color, 200%);
266 | fadein: fadein(@color, 200%, relative);
267 | `;
268 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
269 | });
270 | test('Increase the transparency (or decrease the opacity) of a color, making it less opaque.', () => {
271 | const Div = styled.div`
272 | fadeout: fadeout(hsla(90, 90%, 50%, 0.5), 10%);
273 | fadeout: fadeout(@color, 10%);
274 | fadeout: fadeout(@color, @p);
275 |
276 | fadeout: fadeout(hsla(90, 90%, 50%, 0.5), 10%, relative);
277 | fadeout: fadeout(@color, 10%, relative);
278 | fadeout: fadeout(@color, @p, @r);
279 |
280 | fadeout: fadeout(@color, 200%);
281 | fadeout: fadeout(@color, 200%, relative);
282 | `;
283 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
284 | });
285 |
286 |
287 | test('Set the absolute opacity of a color. Can be applied to colors whether they already have an opacity value or not.', () => {
288 | const Div = styled.div`
289 | fade: fade(hsl(90, 90%, 50%), 10%);
290 | fade: fade(hsl(90, 90%, 50%), @p);
291 | fade: fade(hsl(90, 90%, 50%), 0%);
292 | fade: fade(hsl(90, 90%, 50%), 150%);
293 | `;
294 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
295 | });
296 |
297 |
298 | test('Rotate the hue angle of a color in either direction.', () => {
299 | const Div = styled.div`
300 | spin: spin(hsl(10, 90%, 50%), 30);
301 | spin: spin(hsl(10, 90%, 50%), -30);
302 |
303 | spin: spin(hsl(10, 90%, 50%), @v);
304 | spin: spin(hsl(10, 90%, 50%), -@v);
305 |
306 | spin: spin(hsl(10, 90%, 50%), @v2);
307 | spin: spin(hsl(10, 90%, 50%), -@v2);
308 |
309 | spin: spin(@color, @v);
310 |
311 | spin: spin(@color, @zero);
312 |
313 | spina: spin(hsla(10, 90%, 50%, 0.5), @v2);
314 | spina: spin(hsla(10, 90%, 50%, 0.5), -@v2);
315 | spina: spin(@colora, @v);
316 | `;
317 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
318 | });
319 |
320 |
321 | test('Mix two colors together in variable proportion. Opacity is included in the calculations.', () => {
322 | const Div = styled.div`
323 | mix: mix(#ff0000, #0000ff, 50%);
324 | mix: mix(@a, @b, @p);
325 | mix: mix(rgba(100, 0, 0, 1.0), rgba(0, 100, 0, 1.0));
326 |
327 | mixa: mix(#ff000080, #0000ff80, 50%);
328 | mixa: mix(@aa, @ba, @p);
329 | mixa: mix(rgba(100, 0, 0, 0.5), rgba(0, 100, 0, 0.5));
330 | `;
331 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
332 | });
333 | test('Mix color with white in variable proportion.', () => {
334 | const Div = styled.div`
335 | no-alpha: tint(#007fff, 50%);
336 | no-alpha: tint(@color, @p);
337 | `;
338 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
339 | });
340 | test('Mix color with black in variable proportion.', () => {
341 | const Div = styled.div`
342 | no-alpha: shade(#007fff, 50%);
343 | no-alpha: shade(@color, @p);
344 | `;
345 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
346 | });
347 | test('Remove all saturation from a color in the HSL color space.', () => {
348 | const Div = styled.div`
349 | greyscale1: greyscale(hsl(90, 90%, 50%));
350 | greyscale2: greyscale(@color);
351 | `;
352 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
353 | });
354 | test('Choose which of two colors provides the greatest contrast with another.', () => {
355 | const Div = styled.div`
356 | a: contrast(#bbbbbb);
357 | b: contrast(#222222, #101010);
358 | c: contrast(#222222, #101010, #dddddd);
359 | d: contrast(hsl(90, 100%, 50%), #000000, #ffffff, 30%);
360 | e: contrast(hsl(90, 100%, 50%), #000000, #ffffff, 80%);
361 | `;
362 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
363 | });
--------------------------------------------------------------------------------
/test/Component/Condition.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test('Test and', () => {
7 | const Div = styled.div`
8 | opacity1: if((@errorText) and (@warning), 1, 0);
9 | opacity2: if(@errorText and @warning, 1, 0);
10 | `;
11 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
12 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
13 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
14 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
15 | });
16 |
17 | test('Test or', () => {
18 | const Div = styled.div`
19 | opacity1: if((@errorText) or (@warning), 1, 0);
20 | opacity2: if(@errorText or @warning, 1, 0);
21 | `;
22 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
23 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
24 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
25 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
26 | });
27 |
28 | test('Test =', () => {
29 | const Div = styled.div`
30 | opacity1: if(@a = @b, 1, 0);
31 | `;
32 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
33 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
34 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
35 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
36 | });
37 |
38 | test('Test greater than', () => {
39 | const Div = styled.div`
40 | opacity: if(luma(@bg) > 50%, 1, 0);
41 | opacity: if(luma(@bg) >= 50%, 1, 0);
42 | opacity: if(luma(@bg) < 50%, 1, 0);
43 | opacity: if(luma(@bg) <= 50%, 1, 0);
44 | `;
45 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
46 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
47 | });
48 |
49 | test('If with function', () => {
50 | const Div = styled.div`
51 | cursor: if(@onClick, pointer);
52 | `;
53 | expect(renderer.create(
false}/>).toJSON()).toMatchSnapshot();
54 | });
--------------------------------------------------------------------------------
/test/Component/Extend.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test('Extend a styled div', () => {
7 | const Div = styled.div`
8 | color: @primary;
9 | `;
10 | const Div2 = styled(Div)`
11 | color: @primary;
12 | `;
13 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
14 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
15 | });
16 |
17 | test('Extend styled-components example', () => {
18 | // The Button from the last section without the interpolations
19 | const Button = styled.button`
20 | color: palevioletred;
21 | font-size: 1em;
22 | margin: 1em;
23 | padding: 0.25em 1em;
24 | border: 2px solid palevioletred;
25 | border-radius: 3px;
26 | `;
27 |
28 | // We're extending Button with some extra styles
29 | const TomatoButton = styled(Button)`
30 | color: @color;
31 | border-color: tomato;
32 | `;
33 | expect(renderer.create(
34 |
35 | Tomato Button
36 |
).toJSON()).toMatchSnapshot();
37 | });
--------------------------------------------------------------------------------
/test/Component/Functional.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test('Darkens the primary color 20%', () => {
7 | const Div = styled.div`
8 | color: darken(@primary, 20%);
9 | `;
10 | const tree = renderer.create(
).toJSON();
11 | expect(tree).toMatchSnapshot();
12 | });
13 |
14 | test('Darkens the colors in linear-gradient', () => {
15 | const Div = styled.div`
16 | background: linear-gradient(lighten(@start, 20%) 0%, darken(@end, 20%) 100%);
17 | `;
18 | const tree = renderer.create(
).toJSON();
19 | expect(tree).toMatchSnapshot();
20 | });
--------------------------------------------------------------------------------
/test/Component/ImportFromScopedNPM.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from "styled-components";
4 | import 'jest-styled-components';
5 |
6 | test('Support import from scoped npm', () => {
7 | const Div = styled.div`
8 | @import "./import-scoped";
9 | color: @foo;
10 | `;
11 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
12 | });
--------------------------------------------------------------------------------
/test/Component/Imports.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled, {css} from "styled-components";
4 | import 'jest-styled-components';
5 |
6 | test('Support import', () => {
7 | const Div = styled.div`
8 | @import "import.less";
9 | color: @color;
10 | .foo;
11 | `;
12 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
13 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
14 | });
15 |
16 | test('Support import reference', () => {
17 | const Div = styled.div`
18 | @import (reference) "import.less";
19 | color: @color;
20 | .foo;
21 | `;
22 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
23 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
24 | });
--------------------------------------------------------------------------------
/test/Component/Javascript.test.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import renderer from "react-test-renderer";
3 | import styled from "styled-components";
4 | import "jest-styled-components";
5 |
6 | test("Support javascript", () => {
7 | const Div = styled.div`
8 | @import "javascript.less";
9 | @color: green;
10 | color: @echoColor(@color);
11 | background: @primary-1;
12 | border: 1px solid @primary-2;
13 | `;
14 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
15 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
16 | });
17 |
--------------------------------------------------------------------------------
/test/Component/Less.test.js:
--------------------------------------------------------------------------------
1 | import less from "less";
2 |
3 | test('Less should still compile normally', () => {
4 | const transpileLess = require("../../src/visitors/transpileLess").default;
5 | transpileLess("", "");
6 |
7 | const input = `
8 | @color: red;
9 | div {
10 | color: @color;
11 | darken: darken(@color, 20%);
12 | }
13 | `;
14 | less.render(input).then(({css}) => {
15 | expect(css).toMatchSnapshot();
16 | });
17 | });
--------------------------------------------------------------------------------
/test/Component/List.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test.skip('Returns the number of elements in a value list', () => {
7 | const Div = styled.div`
8 | @list: "banana", "tomato", "potato", "peach";
9 | n: length(@list);
10 | n2: length(1px solid #0080ff);
11 | `;
12 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
13 | });
14 |
15 | test.skip('Returns the value at a specified position in a list.', () => {
16 | const Div = styled.div`
17 | @list: apple, pear, coconut, orange;
18 | value: extract(@list, 3);
19 | `;
20 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
21 | });
--------------------------------------------------------------------------------
/test/Component/Math.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test('Does some math.', () => {
7 | const Div = styled.div`
8 | width: 100px + 100;
9 | width: 100 + 100px;
10 | width1: @a + @b;
11 | width1: @a - @b;
12 | width1: @a * @b;
13 | width1: @a / @b;
14 |
15 | width2: @b + @a;
16 | width2: @b - @a;
17 | width2: @b * @a;
18 | width2: @b / @a;
19 |
20 | width3: @a + @a + @a;
21 | width3: (@a + @a + @a) / 3;
22 | `;
23 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
24 | });
25 |
26 | test('Rounds up to the next highest integer.', () => {
27 | const Div = styled.div`
28 | ceil: ceil(2.4);
29 | ceil: ceil(@value);
30 | ceil: ceil(2.4px);
31 | ceil: ceil(@value2);
32 | `;
33 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
34 | });
35 |
36 | test('Rounds down to the next lowest integer.', () => {
37 | const Div = styled.div`
38 | floor: floor(2.6);
39 | floor: floor(@value);
40 | floor: floor(2.6em);
41 | floor: floor(@value2);
42 | `;
43 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
44 | });
45 |
46 | test('Converts a floating point number into a percentage string.', () => {
47 | const Div = styled.div`
48 | p: percentage(0.5);
49 | p: percentage(0.5em);
50 | p: percentage(@value);
51 | `;
52 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
53 | });
54 |
55 | test('Applies rounding.', () => {
56 | const Div = styled.div`
57 | round: round(1.67);
58 | round: round(@value);
59 | round: round(1.67px);
60 | round: round(@value2);
61 | `;
62 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
63 | });
64 |
65 | test('Calculates square root of a number. Keeps units as they are.', () => {
66 | const Div = styled.div`
67 | sqrt: sqrt(25cm);
68 | sqrt: sqrt(@value);
69 | `;
70 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
71 | });
72 |
73 | test('Calculates absolute value of a number. Keeps units as they are.', () => {
74 | const Div = styled.div`
75 | abs: abs(25cm);
76 | abs: abs(-18.6%);
77 | abs: abs(@value);
78 | abs: abs(@value2);
79 | `;
80 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
81 | });
82 |
83 | test('Calculates sine function.', () => {
84 | const Div = styled.div`
85 | sin: sin(@value); // sine of 1 radian
86 | deg: sin(1deg); // sine of 1 degree
87 | grad: sin(1grad); // sine of 1 gradian
88 | turn: sin(0.2turn); // sine of 1 gradian
89 | `;
90 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
91 | });
92 |
93 | test('Calculates arcsine (inverse of sine) function.', () => {
94 | const Div = styled.div`
95 | asin: asin(0.5);
96 | asin: asin(@zero);
97 | asin: asin(2);
98 | `;
99 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
100 | });
101 |
102 | test('Calculates cosine function.', () => {
103 | const Div = styled.div`
104 | sin: cos(@value); // cos of 1 radian
105 | deg: cos(1deg); // cos of 1 degree
106 | grad: cos(1grad); // cos of 1 gradian
107 | turn: cos(0.2turn); // cos of 1 gradian
108 | `;
109 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
110 | });
111 |
112 | test('Calculates arccosine (inverse of cosine) function.', () => {
113 | const Div = styled.div`
114 | acos: acos(0.5);
115 | acos: acos(@one);
116 | acos: acos(2);
117 | `;
118 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
119 | });
120 |
121 | test('Calculates tangent function.', () => {
122 | const Div = styled.div`
123 | tan: tan(1); // tangent of 1 radian
124 | tan: tan(1deg); // tangent of 1 degree
125 | tan: tan(1grad); // tangent of 1 gradian
126 | `;
127 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
128 | });
129 |
130 | test('Calculates arctangent (inverse of tangent) function.', () => {
131 | const Div = styled.div`
132 | atan: atan(-1.5574077246549023);
133 | atan: atan(@zero);
134 | atan: round(atan(22), 6); // arctangent of 22 rounded to 6 decimal places
135 | `;
136 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
137 | });
138 |
139 | test('PI', () => {
140 | const Div = styled.div`
141 | pi: pi();
142 | `;
143 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
144 | });
145 |
146 | test('Returns the value of the first argument raised to the power of the second argument.', () => {
147 | const Div = styled.div`
148 | pow: pow(0cm, 0px);
149 | pow: pow(25, -1);
150 | pow: pow(25, 0.5);
151 | pow: pow(-25, 0.5);
152 | pow: pow(-25%, -0.5);
153 | pow: pow(@x, @y);
154 | `;
155 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
156 | });
157 |
158 | test('Returns the value of the first argument modulus second argument.', () => {
159 | const Div = styled.div`
160 | mod: mod(0cm, 0px);
161 | mod: mod(11cm, 6px);
162 | mod: mod(-26%, -5);
163 | mod: mod(@x, @y);
164 | `;
165 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
166 | });
167 |
168 | test('Returns the lowest of one or more values.', () => {
169 | const Div = styled.div`
170 | min: min(5, 10);
171 | min: min(3px, 42px, 2px, 16px);
172 | min: min(@a, @b, @c);
173 | `;
174 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
175 | });
176 |
177 | test('Returns the highest of one or more values.', () => {
178 | const Div = styled.div`
179 | max: max(5, 10);
180 | max: max(3%, 42%, 1%, 16%);
181 | max: max(@a, @b, @c);
182 | `;
183 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
184 | });
185 |
186 | test('Does some conditional math.', () => {
187 | const Div = styled.div`
188 | a: if(boolean(true), @a + @b, @a - @b);
189 | b: if(boolean(false), @a + @b, @a - @b);
190 | `;
191 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
192 | });
--------------------------------------------------------------------------------
/test/Component/Mixins.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled, {css} from "styled-components";
4 | import 'jest-styled-components';
5 |
6 | test('Support inline mixins', () => {
7 | const Div = styled.div`
8 | .my-mixin {
9 | color: @color;
10 | }
11 | .my-other-mixin() {
12 | background: @background;
13 | }
14 | .class {
15 | .my-mixin();
16 | .my-other-mixin();
17 | }
18 | `;
19 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
20 | });
21 |
22 | test.skip('Test mixin guards', () => {
23 | const Div = styled.div`
24 | .mixin(@a) when (lightness(@a) >= 50%) {
25 | background-color: black;
26 | }
27 | .mixin(@a) when (lightness(@a) < 50%) {
28 | background-color: white;
29 | }
30 | .mixin(@a) {
31 | color: @a;
32 | }
33 | .class1 { .mixin(#ddd) }
34 | .class2 { .mixin(#555) }
35 | `;
36 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
37 | });
38 |
39 | // test.skip('Test Less loops', () => {
40 | // const Div = styled.div`
41 | // .make-variants(@i:1) when (@i =< 3) {
42 | // .variant-@{i} {
43 | // width: @i * 40px;
44 | // height: @i * 20px;
45 | // background-color: orange;
46 | // margin-bottom: 10px;
47 | // }
48 | // .make-variants(@i + 1); // increment function
49 | // }
50 | // .make-variants();
51 | // `;
52 | // expect(renderer.create(
).toJSON()).toMatchSnapshot();
53 | // });
--------------------------------------------------------------------------------
/test/Component/NestedImports/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@babel/preset-env",
4 | "@babel/preset-react"
5 | ],
6 | "plugins": [
7 | "../../../"
8 | ]
9 | }
--------------------------------------------------------------------------------
/test/Component/NestedImports/NestedImports.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test('#29, nested imports', () => {
7 | const Div = styled.div`
8 | @import "tmp.less";
9 | @import (reference) "reference.less";
10 | &.light {
11 | color: @text-color;
12 | background: @layout-sider-background-light;
13 | }
14 |
15 | &.dark {
16 | background: @layout-header-background;
17 | color: @layout-trigger-color;
18 | }
19 | `;
20 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
21 | });
--------------------------------------------------------------------------------
/test/Component/NestedImports/__snapshots__/NestedImports.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`#29, nested imports 1`] = `
4 | .c0 .test2 {
5 | color: test2;
6 | }
7 |
8 | .c0 .test {
9 | color: test;
10 | }
11 |
12 | .c0 .tmp {
13 | color: tmp;
14 | }
15 |
16 | .c0.light {
17 | color: pink;
18 | background: #222;
19 | }
20 |
21 | .c0.dark {
22 | background: #333;
23 | color: #444;
24 | }
25 |
26 |
29 | `;
30 |
--------------------------------------------------------------------------------
/test/Component/NestedImports/reference.less:
--------------------------------------------------------------------------------
1 | .i-should-not-display {
2 | color: black;
3 | }
4 |
5 | @layout-sider-background-light: #222;
6 | @layout-header-background: #333;
7 | @layout-trigger-color: #444;
--------------------------------------------------------------------------------
/test/Component/NestedImports/test.less:
--------------------------------------------------------------------------------
1 | @import "test2.less";
2 |
3 | @testColor: test;
4 | .test {
5 | color: @testColor;
6 | }
--------------------------------------------------------------------------------
/test/Component/NestedImports/test2.less:
--------------------------------------------------------------------------------
1 | @test2Color: test2;
2 | .test2 {
3 | color: @test2Color;
4 | }
5 |
6 | @text-color: pink;
--------------------------------------------------------------------------------
/test/Component/NestedImports/tmp.less:
--------------------------------------------------------------------------------
1 | @import "./test.less";
2 |
3 | @tmpColor: tmp;
4 | .tmp {
5 | color: @tmpColor;
6 | }
7 |
--------------------------------------------------------------------------------
/test/Component/String.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test('String characters @url', () => {
7 | const Div = styled.div`
8 | background-image: url('images/lamp-post.png?v=1');
9 | `;
10 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
11 | });
--------------------------------------------------------------------------------
/test/Component/StyledComponent.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled, {css} from "styled-components";
4 | import 'jest-styled-components';
5 |
6 | test('Support the styled-components syntax', () => {
7 | const Div = styled.div`
8 | width: ${400}px;
9 | width: 400px;
10 | border: 1px solid #000;
11 | border: ${"1px"} ${"solid"} ${"#000"};
12 | background: ${props => props.primary ? 'palevioletred' : 'white'};
13 | color: ${props => props.primary ? 'white' : 'palevioletred'};
14 | color2: ${props => props.noChild && "#5cb85c"}; // @brand-success
15 | color3: @color;
16 | ${props => props.disabled ? "" : "box-shadow: inset 0 0 0 30px rgba(255, 255, 255, 0.3)"};
17 | `;
18 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
19 | });
20 |
21 | test('Attaching additional props', () => {
22 | const Input = styled.input.attrs(props => ({
23 | // we can define static props
24 | type: 'password',
25 |
26 | // or we can define dynamic ones
27 | margin: props.size || '1em',
28 | padding: props.size || '1em'
29 | }))`
30 | color: palevioletred;
31 | font-size: 1em;
32 | border: 2px solid palevioletred;
33 | border-radius: 3px;
34 |
35 | /* here we use the dynamically computed props */
36 | margin: ${props => props.margin};
37 | padding: ${props => props.padding};
38 |
39 | margin2: @margin;
40 | padding2: @padding;
41 | `;
42 | expect(renderer.create(
43 |
44 |
45 |
46 |
).toJSON()).toMatchSnapshot();
47 | });
48 |
49 | test('Support the styled-components css', () => {
50 | const Div = styled.div`
51 | padding: @padding;
52 | ${props => props.bordered && css`
53 | border: 1px solid @border;
54 | `}
55 | `;
56 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
57 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
58 | });
59 |
60 | test('Support @media queries', () => {
61 | const Div = styled.div`
62 | @media screen and (min-width: 900px) {
63 | article {
64 | padding: @padding;
65 | }
66 | }
67 | `;
68 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
69 | });
70 |
71 | test('Support &&&', () => {
72 | const Div = styled.div`
73 | &&& {
74 | color: palevioletred;
75 | font-weight: @bold;
76 | }
77 | &&&second {
78 | color: red;
79 | }
80 | `;
81 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
82 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
83 | });
84 |
85 | test('Support Element', () => {
86 | const Div = styled.div`
87 | a {
88 | color: red;
89 | &.is-focused:not(.is-open) > .Select-control {
90 | cursor: text;
91 | }
92 | }
93 | `;
94 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
95 | });
96 |
97 | test('Support placeholder on the root', () => {
98 | const Div = styled.div`
99 | &::placeholder {
100 | color: HSL(216, 15%, 65%);
101 | }
102 | `;
103 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
104 | });
105 |
106 | test('Support styling other components', () => {
107 | const Child1 = styled.div`
108 | color: brown;
109 | `;
110 | const Child2 = styled.div`
111 | color: red;
112 | `;
113 | const Div = styled.div`
114 | ${Child1},
115 | ${Child2}{
116 | width: 400px;
117 | }
118 | `;
119 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
120 | });
121 |
122 | test('Support SC mixins', () => {
123 | const hover = css`
124 | &:hover {
125 | text-decoration: underline;
126 | }
127 | `;
128 | const Icon = styled.div``;
129 | const Div = styled.div`
130 | ${hover};
131 | ${props => hover};
132 | border-bottom: @color;
133 |
134 | &:hover, &:hover ${Icon} {
135 | color: inherit;
136 | }
137 | `;
138 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
139 | });
140 |
141 | test('#20, not', () => {
142 | const Div = styled.div`
143 | box-shadow: if(not (@disabled), inset 0 0 0 30px red);
144 | `;
145 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
146 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
147 | });
148 |
149 | test('#20, box-shadow', () => {
150 | const Div = styled.div`
151 | box-shadow: if(not @disabled, inset 0 0 0 30px rgba(255, 255, 255, 0.5));
152 | `;
153 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
154 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
155 | });
156 |
157 | test('#39, box-shadow', () => {
158 | const Div = styled.div`
159 | .column {
160 | &.frozen&:empty::before {
161 | content: '\\200B';
162 | }
163 | }
164 | `;
165 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
166 | });
167 |
168 | test('Allow rules missing the last semi-colon', () => {
169 | const Div = styled.div`
170 | missing-semi-colon: @yes
171 | `;
172 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
173 | });
--------------------------------------------------------------------------------
/test/Component/Type.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test('Returns true if a value is a number, false otherwise.', () => {
7 | const Div = styled.div`
8 | number1: isnumber(#ff0); // false
9 | number2: isnumber(blue); // false
10 | number3: isnumber("string"); // false
11 | number4: isnumber(1234); // true
12 | number5: isnumber(56px); // true
13 | number6: isnumber(7.8%); // true
14 | number7: isnumber(keyword); // false
15 | number8: isnumber(url("http://yadi")); // false
16 | `;
17 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
18 |
19 | const Div2 = styled.div`
20 | number1: isnumber(@v1); // false
21 | number2: isnumber(@v2); // false
22 | number3: isnumber(@v3); // false
23 | number4: isnumber(@v4); // true
24 | number5: isnumber(@v5); // true
25 | number6: isnumber(@v6); // true
26 | number7: isnumber(@v7); // false
27 | number8: isnumber(@v8); // false
28 | `;
29 | expect(renderer.create(
).toJSON()).toMatchSnapshot();
30 | });
31 |
32 | test('Returns true if a value is a string, false otherwise.', () => {
33 | const Div = styled.div`
34 | string1: isstring(#ff0); // false
35 | string2: isstring(blue); // false
36 | string3: isstring("string"); // true
37 | string4: isstring(1234); // false
38 | string5: isstring(56px); // false
39 | string6: isstring(7.8%); // false
40 | string7: isstring(keyword); // false
41 | string8: isstring(url("http://yadi")); // false
42 | `;
43 | expect(renderer.create().toJSON()).toMatchSnapshot();
44 |
45 | const Div2 = styled.div`
46 | string1: isstring(@v1); // false
47 | string2: isstring(@v2); // false
48 | string3: isstring(@v3); // true
49 | string4: isstring(@v4); // false
50 | string5: isstring(@v5); // false
51 | string6: isstring(@v6); // false
52 | string7: isstring(@v7); // false
53 | string1: isstring(@v8); // false
54 | `;
55 | expect(renderer.create().toJSON()).toMatchSnapshot();
56 | });
57 |
58 | test('Returns true if a value is a color, false otherwise.', () => {
59 | const Div = styled.div`
60 | v1: iscolor(#ff0); // true
61 | v2: iscolor(blue); // true
62 | v3: iscolor("string"); // false
63 | v4: iscolor(1234567); // false
64 | v5: iscolor(56px); // false
65 | v6: iscolor(7.8%); // false
66 | v7: iscolor(keyword); // false
67 | v8: iscolor(url("http://yadi")); // false
68 | `;
69 | expect(renderer.create().toJSON()).toMatchSnapshot();
70 |
71 | const Div2 = styled.div`
72 | v1: iscolor(@v1); // true
73 | v2: iscolor(@v2); // true
74 | v3: iscolor(@v3); // false
75 | v4: iscolor(@v4); // false
76 | v5: iscolor(@v5); // false
77 | v6: iscolor(@v6); // false
78 | v7: iscolor(@v7); // false
79 | v8: iscolor(@v8); // false
80 | `;
81 | expect(renderer.create().toJSON()).toMatchSnapshot();
82 | });
83 |
84 | test('Returns true if a value is a number in pixels, false otherwise.', () => {
85 | const Div = styled.div`
86 | is: ispixel(56px);
87 | `;
88 | expect(renderer.create().toJSON()).toMatchSnapshot();
89 |
90 | const Div2 = styled.div`
91 | is: ispixel(@v);
92 | `;
93 | expect(renderer.create().toJSON()).toMatchSnapshot();
94 | });
95 |
96 | test('Returns true if a value is an em value, false otherwise.', () => {
97 | const Div = styled.div`
98 | is: isem(56em);
99 | `;
100 | expect(renderer.create().toJSON()).toMatchSnapshot();
101 |
102 | const Div2 = styled.div`
103 | is: isem(@v);
104 | `;
105 | expect(renderer.create().toJSON()).toMatchSnapshot();
106 | });
107 |
108 | test('Returns: true if value is a percentage value, false otherwise.', () => {
109 | const Div = styled.div`
110 | is: ispercentage(7.8%);
111 | `;
112 | expect(renderer.create().toJSON()).toMatchSnapshot();
113 |
114 | const Div2 = styled.div`
115 | is: ispercentage(@v);
116 | `;
117 | expect(renderer.create().toJSON()).toMatchSnapshot();
118 | });
119 |
120 | test.skip('Returns: true if value is a number in specific units, false otherwise.', () => {
121 | const Div = styled.div`
122 | is: isunit(11px, px);
123 | `;
124 | expect(renderer.create().toJSON()).toMatchSnapshot();
125 |
126 | const Div2 = styled.div`
127 | is: isunit(@v, %);
128 | width: @v;
129 | `;
130 | expect(renderer.create().toJSON()).toMatchSnapshot();
131 | });
--------------------------------------------------------------------------------
/test/Component/Variable.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import styled from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | test('Takes the color from props', () => {
7 | const Div = styled.div`
8 | background-color: chocolate;
9 | color: @primary;
10 | `;
11 | const tree = renderer.create().toJSON();
12 | expect(tree).toMatchSnapshot();
13 | });
14 |
15 | test('Replaces single variable in linear-gradient', () => {
16 | const Div = styled.div`
17 | background: linear-gradient(@start 0%, @end 100%);
18 | `;
19 | const tree = renderer.create().toJSON();
20 | expect(tree).toMatchSnapshot();
21 | });
22 |
23 | test('Use the color defiened in the component', () => {
24 | const Div = styled.div`
25 | @main: palevioletred;
26 | color: @main;
27 | `;
28 | expect(renderer.create().toJSON()).toMatchSnapshot();
29 | });
30 |
31 | test('#32, Fail to escape variable with string and variable', () => {
32 | const Div = styled.div`
33 | @font-family-no-number : "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
34 | @font-family : "Monospaced Number", @font-family-no-number;
35 | font-family: @font-family;
36 | `;
37 | expect(renderer.create().toJSON()).toMatchSnapshot();
38 | });
39 |
40 | test('#32, Fail to escape variable with string and variable from import', () => {
41 | const Div = styled.div`
42 | @import (reference) "import.less";
43 | font-family: @font-family;
44 | `;
45 | expect(renderer.create().toJSON()).toMatchSnapshot();
46 | expect(renderer.create().toJSON()).toMatchSnapshot();
47 | });
48 |
49 | test('Nested variables', () => {
50 | const Div = styled.div`
51 | @font-family3 : "Third";
52 | @font-family2 : "Number", @font-family3;
53 | @font-family1 : "Monospaced", @font-family2;
54 | font-family: "root", @font-family1;
55 | `;
56 | expect(renderer.create().toJSON()).toMatchSnapshot();
57 | expect(renderer.create().toJSON()).toMatchSnapshot();
58 | });
59 |
60 | test('#34', () => {
61 | const Link = styled.div``;
62 | const antBtnClassName = "ant-btn";
63 | const size = {xlarge: "3.2rem"};
64 | const AntButton = styled(Link)`
65 | fluid: @fluid;
66 | &.${antBtnClassName} {
67 | font-size: ${size.xlarge};
68 | font-weight: 700;
69 | width: 40px;
70 | text-decoration: none;
71 | padding: @padding;
72 |
73 | &,
74 | &:hover,
75 | &:focus,
76 | &:active,
77 | &.active {
78 | background: none;
79 | border-color: transparent;
80 | }
81 | }
82 | `;
83 | const Div = styled(({fluid, ...rest}) => )`
84 | && {
85 | width: if(@fluid, 100%, auto);
86 | }
87 | `;
88 | expect(renderer.create().toJSON()).toMatchSnapshot();
89 | expect(renderer.create().toJSON()).toMatchSnapshot();
90 | });
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Boolean.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Sets a complex variable in an if check 1`] = `
4 |
7 | `;
8 |
9 | exports[`Sets a complex variable in an if check 2`] = `
10 | .c0 {
11 | cursor: not-allowed;
12 | }
13 |
14 |
18 | `;
19 |
20 | exports[`Sets color to the inverse of the bg luma 1`] = `
21 | .c0 {
22 | background: #001F3F;
23 | color: white;
24 | }
25 |
26 |
30 | `;
31 |
32 | exports[`Sets color to the inverse of the bg luma 2`] = `
33 | .c0 {
34 | background: white;
35 | color: black;
36 | }
37 |
38 |
41 | `;
42 |
43 | exports[`Sets conditional margins 1`] = `
44 |
47 | `;
48 |
49 | exports[`Sets conditional margins 2`] = `
50 | .c0 {
51 | margin: 6px;
52 | }
53 |
54 |
57 | `;
58 |
59 | exports[`Sets conditional margins with variables 1`] = `
60 | .c0 {
61 | margin: 0px;
62 | }
63 |
64 |
67 | `;
68 |
69 | exports[`Sets conditional margins with variables 2`] = `
70 | .c0 {
71 | margin: 20px;
72 | }
73 |
74 |
77 | `;
78 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Color.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Calculates the luma (perceptual brightness) of a color object. 1`] = `
4 | .c0 {
5 | luma: 44.111615679100964;
6 | luma: 44.111615679100964;
7 | }
8 |
9 |
13 | `;
14 |
15 | exports[`Calculates the value of the luma without gamma correction. 1`] = `
16 | .c0 {
17 | luminance: 65.28078431372549;
18 | luminance: 65.28078431372549;
19 | luminance: 32.640392156862745;
20 | }
21 |
22 |
26 | `;
27 |
28 | exports[`Choose which of two colors provides the greatest contrast with another. 1`] = `
29 | .c0 {
30 | a: #000;
31 | b: #FFF;
32 | c: #dddddd;
33 | d: #000000;
34 | e: #ffffff;
35 | }
36 |
37 |
40 | `;
41 |
42 | exports[`Creates a hex representation of a color in #AARRGGBB 1`] = `
43 | .c0 {
44 | argb: #805a1794;
45 | argb: #805a1794;
46 | }
47 |
48 |
52 | `;
53 |
54 | exports[`Creates an opaque color object from decimal red, green and blue (RGB) values. 1`] = `
55 | .c0 {
56 | rgb: #5a8120;
57 | rgba: rgba(90,129,32,0.5);
58 | rgb: #5a8120;
59 | rgba: rgba(90,129,32,0.5);
60 | rgb: rgb(90,129,32);
61 | rgba: rgba(90,129,32,0.5);
62 | rgb: rgb(90,129,32);
63 | rgba: rgba(90,129,32,0.5);
64 | rgb: rgb(255,255,255);
65 | }
66 |
67 |
71 | `;
72 |
73 | exports[`Creates an opaque color object from hue, saturation and lightness (HSL) values. 1`] = `
74 | .c0 {
75 | hsl: #80ff00;
76 | hsl1: #80ff00;
77 | new: #e6f1da;
78 | hsla: rgba(128,255,0,0.5);
79 | hsla: rgba(128,255,0,0.5);
80 | }
81 |
82 |
85 | `;
86 |
87 | exports[`Creates an opaque color object from hue, saturation and value (HSV) values. 1`] = `
88 | .c0 {
89 | hsv1: #408000;
90 | hsv2: #408000;
91 | hsva1: rgba(64,128,0,0.5);
92 | hsva2: rgba(64,128,0,0.5);
93 | }
94 |
95 |
98 | `;
99 |
100 | exports[`Decrease the lightness of a color in the HSL color space by an absolute amount. 1`] = `
101 | .c0 {
102 | darken: rgb(77,138,15);
103 | darken: rgb(77,138,15);
104 | darken: rgb(77,138,15);
105 | darkena: rgba(77,138,15,0.5);
106 | darkena: rgba(77,138,15,0.5);
107 | darkena: rgba(77,138,15,0.5);
108 | }
109 |
110 |
114 | `;
115 |
116 | exports[`Decrease the saturation of a color in the HSL color space by an absolute amount. 1`] = `
117 | .c0 {
118 | desaturate: rgb(128,204,51);
119 | desaturate: rgb(128,204,51);
120 | desaturate: rgb(128,204,51);
121 | desaturatea: rgba(128,204,51,0.5);
122 | desaturatea: rgba(128,204,51,0.5);
123 | desaturatea: rgba(128,204,51,0.5);
124 | }
125 |
126 |
130 | `;
131 |
132 | exports[`Decrease the transparency (or increase the opacity) of a color, making it more opaque. Has no effect on opaque colors. 1`] = `
133 | .c0 {
134 | fadein: rgba(128,242,13,0.6);
135 | fadein: rgba(128,242,13,0.6);
136 | fadein: rgba(128,242,13,0.6);
137 | fadein: rgba(128,242,13,0.55);
138 | fadein: rgba(128,242,13,0.55);
139 | fadein: rgba(128,242,13,0.55);
140 | fadein: rgb(128,242,13);
141 | fadein: rgb(128,242,13);
142 | }
143 |
144 |
149 | `;
150 |
151 | exports[`Extract and reconstruct an hsl color. 1`] = `
152 | .c0 {
153 | col-before: #80bf40;
154 | col-after: #80bf40;
155 | }
156 |
157 |
160 | `;
161 |
162 | exports[`Extract and reconstruct an hsl color. 2`] = `
163 | .c0 {
164 | col-before: #80ff00;
165 | col-after: #80ff00;
166 | }
167 |
168 |
171 | `;
172 |
173 | exports[`Extract and reconstruct an hsv color. 1`] = `
174 | .c0 {
175 | col-before: #608040;
176 | col-after: #608040;
177 | }
178 |
179 |
182 | `;
183 |
184 | exports[`Extract and reconstruct an hsv color. 2`] = `
185 | .c0 {
186 | col-before: #80ff00;
187 | col-after: #80ff00;
188 | }
189 |
190 |
193 | `;
194 |
195 | exports[`Extracts the alpha channel of a color object. 1`] = `
196 | .c0 {
197 | alpha: 0.5;
198 | alpha: 0.5;
199 | alpha: 0.5;
200 | }
201 |
202 |
207 | `;
208 |
209 | exports[`Extracts the blue channel of a color object. 1`] = `
210 | .c0 {
211 | blue: 30;
212 | blue: 30;
213 | blue: 30;
214 | }
215 |
216 |
221 | `;
222 |
223 | exports[`Extracts the green channel of a color object. 1`] = `
224 | .c0 {
225 | green: 20;
226 | green: 20;
227 | green: 20;
228 | }
229 |
230 |
235 | `;
236 |
237 | exports[`Extracts the hue channel of a color object in the HSL color space. 1`] = `
238 | .c0 {
239 | hue: 90;
240 | hue: 90;
241 | hue: 90;
242 | hue: 90;
243 | }
244 |
245 |
249 | `;
250 |
251 | exports[`Extracts the hue channel of a color object in the HSV color space. 1`] = `
252 | .c0 {
253 | hsvhue: 90;
254 | hsvhue: 90;
255 | hsvhue: 90;
256 | hsvhue: 90;
257 | }
258 |
259 |
263 | `;
264 |
265 | exports[`Extracts the lightness channel of a color object in the HSL color space. 1`] = `
266 | .c0 {
267 | lightness: 50%;
268 | lightness: 50%;
269 | lightness: 50%;
270 | lightness: 50%;
271 | lightness: 50%;
272 | }
273 |
274 |
278 | `;
279 |
280 | exports[`Extracts the red channel of a color object. 1`] = `
281 | .c0 {
282 | red: 10;
283 | red: 10;
284 | red: 10;
285 | }
286 |
287 |
292 | `;
293 |
294 | exports[`Extracts the saturation channel of a color object in the HSL color space. 1`] = `
295 | .c0 {
296 | saturation: 100%;
297 | saturation: 100%;
298 | saturation: 100%;
299 | saturation: 100%;
300 | saturation: 50%;
301 | }
302 |
303 |
307 | `;
308 |
309 | exports[`Extracts the saturation channel of a color object in the HSV color space. 1`] = `
310 | .c0 {
311 | hsvsaturation: 100%;
312 | hsvsaturation: 100%;
313 | hsvsaturation: 100%;
314 | hsvsaturation: 100%;
315 | hsvsaturation: 50%;
316 | }
317 |
318 |
322 | `;
323 |
324 | exports[`Extracts the value channel of a color object in the HSV color space. 1`] = `
325 | .c0 {
326 | hsvvalue: 50%;
327 | hsvvalue: 50%;
328 | hsvvalue: 50%;
329 | hsvvalue: 50%;
330 | hsvvalue: 50%;
331 | }
332 |
333 |
337 | `;
338 |
339 | exports[`Increase the lightness of a color in the HSL color space by an absolute amount. 1`] = `
340 | .c0 {
341 | lighten: rgb(179,240,117);
342 | lighten: rgb(179,240,117);
343 | lighten: rgb(179,240,117);
344 | lightena: rgba(179,240,117,0.5);
345 | lightena: rgba(179,240,117,0.5);
346 | lightena: rgba(179,240,117,0.5);
347 | }
348 |
349 |
353 | `;
354 |
355 | exports[`Increase the saturation of a color in the HSL color space by an absolute amount. 1`] = `
356 | .c0 {
357 | saturate: rgb(128,255,0);
358 | saturate: rgb(128,255,0);
359 | saturate: rgb(128,255,0);
360 | saturatea: rgba(128,255,0,0.5);
361 | saturatea: rgba(128,255,0,0.5);
362 | saturatea: rgba(128,255,0,0.5);
363 | }
364 |
365 |
369 | `;
370 |
371 | exports[`Increase the transparency (or decrease the opacity) of a color, making it less opaque. 1`] = `
372 | .c0 {
373 | fadeout: rgba(128,242,13,0.4);
374 | fadeout: rgba(128,242,13,0.4);
375 | fadeout: rgba(128,242,13,0.4);
376 | fadeout: rgba(128,242,13,0.45);
377 | fadeout: rgba(128,242,13,0.45);
378 | fadeout: rgba(128,242,13,0.45);
379 | fadeout: rgba(128,242,13,0);
380 | fadeout: rgba(128,242,13,0);
381 | }
382 |
383 |
388 | `;
389 |
390 | exports[`Mix color with black in variable proportion. 1`] = `
391 | .c0 {
392 | no-alpha: rgb(0,64,128);
393 | no-alpha: rgb(0,64,128);
394 | }
395 |
396 |
400 | `;
401 |
402 | exports[`Mix color with white in variable proportion. 1`] = `
403 | .c0 {
404 | no-alpha: rgb(128,191,255);
405 | no-alpha: rgb(128,191,255);
406 | }
407 |
408 |
412 | `;
413 |
414 | exports[`Mix two colors together in variable proportion. Opacity is included in the calculations. 1`] = `
415 | .c0 {
416 | mix: rgb(128,0,128);
417 | mix: rgb(128,0,128);
418 | mix: rgb(50,50,0);
419 | mixa: rgba(128,0,128,0.5);
420 | mixa: rgba(128,0,128,0.5);
421 | mixa: rgba(50,50,0,0.5);
422 | }
423 |
424 |
427 | `;
428 |
429 | exports[`Remove all saturation from a color in the HSL color space. 1`] = `
430 | .c0 {
431 | greyscale1: rgb(128,128,128);
432 | greyscale2: rgb(128,128,128);
433 | }
434 |
435 |
439 | `;
440 |
441 | exports[`Rotate the hue angle of a color in either direction. 1`] = `
442 | .c0 {
443 | spin: rgb(242,165,13);
444 | spin: rgb(242,13,90);
445 | spin: rgb(242,165,13);
446 | spin: rgb(242,13,90);
447 | spin: rgb(242,165,13);
448 | spin: rgb(242,13,90);
449 | spin: rgb(242,166,13);
450 | spin: rgb(242,51,13);
451 | spina: rgba(242,165,13,0.5);
452 | spina: rgba(242,13,90,0.5);
453 | spina: rgba(242,166,13,0.5);
454 | }
455 |
456 |
460 | `;
461 |
462 | exports[`Set the absolute opacity of a color. Can be applied to colors whether they already have an opacity value or not. 1`] = `
463 | .c0 {
464 | fade: rgba(128,242,13,0.1);
465 | fade: rgba(128,242,13,0.1);
466 | fade: rgba(128,242,13,0);
467 | fade: rgb(128,242,13);
468 | }
469 |
470 |
474 | `;
475 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Condition.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`If with function 1`] = `
4 | .c0 {
5 | cursor: pointer;
6 | }
7 |
8 |
12 | `;
13 |
14 | exports[`Test = 1`] = `
15 | .c0 {
16 | opacity1: 1;
17 | }
18 |
19 |
22 | `;
23 |
24 | exports[`Test = 2`] = `
25 | .c0 {
26 | opacity1: 0;
27 | }
28 |
29 |
32 | `;
33 |
34 | exports[`Test = 3`] = `
35 | .c0 {
36 | opacity1: 1;
37 | }
38 |
39 |
42 | `;
43 |
44 | exports[`Test = 4`] = `
45 | .c0 {
46 | opacity1: 0;
47 | }
48 |
49 |
52 | `;
53 |
54 | exports[`Test and 1`] = `
55 | .c0 {
56 | opacity1: 0;
57 | opacity2: 0;
58 | }
59 |
60 |
63 | `;
64 |
65 | exports[`Test and 2`] = `
66 | .c0 {
67 | opacity1: 0;
68 | opacity2: 0;
69 | }
70 |
71 |
74 | `;
75 |
76 | exports[`Test and 3`] = `
77 | .c0 {
78 | opacity1: 0;
79 | opacity2: 0;
80 | }
81 |
82 |
85 | `;
86 |
87 | exports[`Test and 4`] = `
88 | .c0 {
89 | opacity1: 1;
90 | opacity2: 1;
91 | }
92 |
93 |
96 | `;
97 |
98 | exports[`Test greater than 1`] = `
99 | .c0 {
100 | opacity: 0;
101 | opacity: 0;
102 | opacity: 1;
103 | opacity: 1;
104 | }
105 |
106 |
109 | `;
110 |
111 | exports[`Test greater than 2`] = `
112 | .c0 {
113 | opacity: 1;
114 | opacity: 1;
115 | opacity: 0;
116 | opacity: 0;
117 | }
118 |
119 |
122 | `;
123 |
124 | exports[`Test or 1`] = `
125 | .c0 {
126 | opacity1: 0;
127 | opacity2: 0;
128 | }
129 |
130 |
133 | `;
134 |
135 | exports[`Test or 2`] = `
136 | .c0 {
137 | opacity1: 1;
138 | opacity2: 1;
139 | }
140 |
141 |
144 | `;
145 |
146 | exports[`Test or 3`] = `
147 | .c0 {
148 | opacity1: 1;
149 | opacity2: 1;
150 | }
151 |
152 |
155 | `;
156 |
157 | exports[`Test or 4`] = `
158 | .c0 {
159 | opacity1: 1;
160 | opacity2: 1;
161 | }
162 |
163 |
166 | `;
167 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Extend.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Extend a styled div 1`] = `
4 | .c0 {
5 | color: red;
6 | }
7 |
8 |
11 | `;
12 |
13 | exports[`Extend a styled div 2`] = `
14 | .c0 {
15 | color: red;
16 | color: red;
17 | }
18 |
19 |
22 | `;
23 |
24 | exports[`Extend styled-components example 1`] = `
25 | .c0 {
26 | color: palevioletred;
27 | font-size: 1em;
28 | margin: 1em;
29 | padding: 0.25em 1em;
30 | border: 2px solid palevioletred;
31 | border-radius: 3px;
32 | }
33 |
34 | .c1 {
35 | color: palevioletred;
36 | font-size: 1em;
37 | margin: 1em;
38 | padding: 0.25em 1em;
39 | border: 2px solid palevioletred;
40 | border-radius: 3px;
41 | color: tomato;
42 | border-color: tomato;
43 | }
44 |
45 |
46 |
51 |
57 |
58 | `;
59 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Functional.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Darkens the colors in linear-gradient 1`] = `
4 | .c0 {
5 | background: linear-gradient(rgb(255,102,102) 0%,rgb(0,0,153) 100%);
6 | }
7 |
8 |
13 | `;
14 |
15 | exports[`Darkens the primary color 20% 1`] = `
16 | .c0 {
17 | color: rgb(153,0,0);
18 | }
19 |
20 |
23 | `;
24 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/ImportFromScopedNPM.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Support import from scoped npm 1`] = `
4 | .c0 {
5 | color: yellow;
6 | }
7 |
8 |
11 | `;
12 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Imports.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Support import 1`] = `
4 | .c0 {
5 | color: green;
6 | background: #900;
7 | border: 1px solid green;
8 | }
9 |
10 | .c0 .foo {
11 | background: #900;
12 | border: 1px solid green;
13 | }
14 |
15 |
18 | `;
19 |
20 | exports[`Support import 2`] = `
21 | .c0 {
22 | color: red;
23 | background: #900;
24 | border: 1px solid red;
25 | }
26 |
27 | .c0 .foo {
28 | background: #900;
29 | border: 1px solid red;
30 | }
31 |
32 |
36 | `;
37 |
38 | exports[`Support import reference 1`] = `
39 | .c0 {
40 | color: green;
41 | background: #900;
42 | border: 1px solid green;
43 | }
44 |
45 |
48 | `;
49 |
50 | exports[`Support import reference 2`] = `
51 | .c0 {
52 | color: red;
53 | background: #900;
54 | border: 1px solid red;
55 | }
56 |
57 |
61 | `;
62 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Javascript.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Support javascript 1`] = `
4 | .c0 {
5 | color: green;
6 | background: #403d3c;
7 | border: 1px solid #403d3c;
8 | }
9 |
10 |
13 | `;
14 |
15 | exports[`Support javascript 2`] = `
16 | .c0 {
17 | color: red;
18 | background: #403d3c;
19 | border: 1px solid #403d3c;
20 | }
21 |
22 |
26 | `;
27 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Less.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Less should still compile normally 1`] = `
4 | "div {
5 | color: red;
6 | darken: #990000;
7 | }
8 | "
9 | `;
10 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/List.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Returns the number of elements in a value list 1`] = `
4 | .c0 {
5 | n: 4;
6 | n2: 3;
7 | }
8 |
9 |
12 | `;
13 |
14 | exports[`Returns the value at a specified position in a list. 1`] = `
15 | .c0 {
16 | value: coconut;
17 | }
18 |
19 |
22 | `;
23 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Math.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Applies rounding. 1`] = `
4 | .c0 {
5 | round: 2;
6 | round: 2;
7 | round: 2px;
8 | round: 2px;
9 | }
10 |
11 |
15 | `;
16 |
17 | exports[`Calculates absolute value of a number. Keeps units as they are. 1`] = `
18 | .c0 {
19 | abs: 25cm;
20 | abs: 18.6%;
21 | abs: 25cm;
22 | abs: 18.6%;
23 | }
24 |
25 |
29 | `;
30 |
31 | exports[`Calculates arccosine (inverse of cosine) function. 1`] = `
32 | .c0 {
33 | acos: 1.0471975511965979rad;
34 | acos: 0rad;
35 | acos: NaNrad;
36 | }
37 |
38 |
41 | `;
42 |
43 | exports[`Calculates arcsine (inverse of sine) function. 1`] = `
44 | .c0 {
45 | asin: 0.5235987755982989rad;
46 | asin: 0rad;
47 | asin: NaNrad;
48 | }
49 |
50 |
53 | `;
54 |
55 | exports[`Calculates arctangent (inverse of tangent) function. 1`] = `
56 | .c0 {
57 | atan: -1rad;
58 | atan: 0rad;
59 | atan: 1.525373rad;
60 | }
61 |
62 |
65 | `;
66 |
67 | exports[`Calculates cosine function. 1`] = `
68 | .c0 {
69 | sin: 0.5403023058681398;
70 | deg: 0.9998476951563913;
71 | grad: 0.9998766324816606;
72 | turn: 0.30901699437494745;
73 | }
74 |
75 |
79 | `;
80 |
81 | exports[`Calculates sine function. 1`] = `
82 | .c0 {
83 | sin: 0.8414709848078965;
84 | deg: 0.01745240643728351;
85 | grad: 0.015707317311820675;
86 | turn: 0.9510565162951535;
87 | }
88 |
89 |
93 | `;
94 |
95 | exports[`Calculates square root of a number. Keeps units as they are. 1`] = `
96 | .c0 {
97 | sqrt: 5cm;
98 | sqrt: 5cm;
99 | }
100 |
101 |
105 | `;
106 |
107 | exports[`Calculates tangent function. 1`] = `
108 | .c0 {
109 | tan: 1.5574077246549023;
110 | tan: 0.017455064928217585;
111 | tan: 0.015709255323664916;
112 | }
113 |
114 |
118 | `;
119 |
120 | exports[`Converts a floating point number into a percentage string. 1`] = `
121 | .c0 {
122 | p: 50%;
123 | p: 50%;
124 | p: 50%;
125 | }
126 |
127 |
131 | `;
132 |
133 | exports[`Does some conditional math. 1`] = `
134 | .c0 {
135 | a: 8;
136 | b: 2;
137 | }
138 |
139 |
142 | `;
143 |
144 | exports[`Does some math. 1`] = `
145 | .c0 {
146 | width: 200px;
147 | width1: 150px;
148 | width1: 50px;
149 | width1: 5000px;
150 | width1: 2px;
151 | width2: 150px;
152 | width2: -50px;
153 | width2: 5000px;
154 | width2: 0.5px;
155 | width3: 300px;
156 | width3: 100px;
157 | }
158 |
159 |
162 | `;
163 |
164 | exports[`PI 1`] = `
165 | .c0 {
166 | pi: 3.14159265;
167 | }
168 |
169 |
172 | `;
173 |
174 | exports[`Returns the highest of one or more values. 1`] = `
175 | .c0 {
176 | max: 10;
177 | max: 42%;
178 | max: 72cm;
179 | }
180 |
181 |
184 | `;
185 |
186 | exports[`Returns the lowest of one or more values. 1`] = `
187 | .c0 {
188 | min: 5;
189 | min: 2px;
190 | min: 3px;
191 | }
192 |
193 |
196 | `;
197 |
198 | exports[`Returns the value of the first argument modulus second argument. 1`] = `
199 | .c0 {
200 | mod: NaNcm;
201 | mod: 5cm;
202 | mod: -1%;
203 | mod: 2;
204 | }
205 |
206 |
211 | `;
212 |
213 | exports[`Returns the value of the first argument raised to the power of the second argument. 1`] = `
214 | .c0 {
215 | pow: 1cm;
216 | pow: 0.04;
217 | pow: 5;
218 | pow: NaN;
219 | pow: NaN%;
220 | pow: 625;
221 | }
222 |
223 |
228 | `;
229 |
230 | exports[`Rounds down to the next lowest integer. 1`] = `
231 | .c0 {
232 | floor: 2;
233 | floor: 2;
234 | floor: 2em;
235 | floor: 2em;
236 | }
237 |
238 |
242 | `;
243 |
244 | exports[`Rounds up to the next highest integer. 1`] = `
245 | .c0 {
246 | ceil: 3;
247 | ceil: 3;
248 | ceil: 3px;
249 | ceil: 3px;
250 | }
251 |
252 |
256 | `;
257 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Mixins.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Support inline mixins 1`] = `
4 | .c0 .my-mixin {
5 | color: red;
6 | }
7 |
8 | .c0 .class {
9 | color: red;
10 | background: white;
11 | }
12 |
13 |
17 | `;
18 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/String.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`String characters @url 1`] = `
4 | .c0 {
5 | background-image: url('images/lamp-post.png?v=1');
6 | }
7 |
8 |
11 | `;
12 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/StyledComponent.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`#20, box-shadow 1`] = `
4 |
7 | `;
8 |
9 | exports[`#20, box-shadow 2`] = `
10 | .c0 {
11 | box-shadow: inset 0 0 0 30px rgba(255,255,255,0.5);
12 | }
13 |
14 |
18 | `;
19 |
20 | exports[`#20, not 1`] = `
21 | .c0 {
22 | box-shadow: inset 0 0 0 30px red;
23 | }
24 |
25 |
28 | `;
29 |
30 | exports[`#20, not 2`] = `
31 |
35 | `;
36 |
37 | exports[`#39, box-shadow 1`] = `
38 | .c0 .column.frozen.column:empty::before {
39 | content: '\\200B';
40 | }
41 |
42 |
45 | `;
46 |
47 | exports[`Allow rules missing the last semi-colon 1`] = `
48 | .c0 {
49 | missing-semi-colon: yes;
50 | }
51 |
52 |
55 | `;
56 |
57 | exports[`Attaching additional props 1`] = `
58 | .c0 {
59 | color: palevioletred;
60 | font-size: 1em;
61 | border: 2px solid palevioletred;
62 | border-radius: 3px;
63 | margin: 1em;
64 | padding: 1em;
65 | margin2: 1em;
66 | padding2: 1em;
67 | }
68 |
69 | .c1 {
70 | color: palevioletred;
71 | font-size: 1em;
72 | border: 2px solid palevioletred;
73 | border-radius: 3px;
74 | margin: 2em;
75 | padding: 2em;
76 | margin2: 2em;
77 | padding2: 2em;
78 | }
79 |
80 |
81 |
87 |
88 |
94 |
95 | `;
96 |
97 | exports[`Support &&& 1`] = `
98 | .c0.c0.c0 {
99 | color: palevioletred;
100 | }
101 |
102 | .c0.c0.c0second {
103 | color: red;
104 | }
105 |
106 |
109 | `;
110 |
111 | exports[`Support &&& 2`] = `
112 | .c0.c0.c0 {
113 | color: palevioletred;
114 | font-weight: bold;
115 | }
116 |
117 | .c0.c0.c0second {
118 | color: red;
119 | }
120 |
121 |
124 | `;
125 |
126 | exports[`Support @media queries 1`] = `
127 | @media screen and (min-width:900px) {
128 | .c0 article {
129 | padding: 1rem;
130 | }
131 | }
132 |
133 |
137 | `;
138 |
139 | exports[`Support Element 1`] = `
140 | .c0 a {
141 | color: red;
142 | }
143 |
144 | .c0 a.is-focused:not(.is-open) > .Select-control {
145 | cursor: text;
146 | }
147 |
148 |
151 | `;
152 |
153 | exports[`Support SC mixins 1`] = `
154 | .c1 {
155 | border-bottom: red;
156 | }
157 |
158 | .c1:hover {
159 | -webkit-text-decoration: underline;
160 | text-decoration: underline;
161 | }
162 |
163 | .c1:hover {
164 | -webkit-text-decoration: underline;
165 | text-decoration: underline;
166 | }
167 |
168 | .c1:hover,
169 | .c1:hover.c0 {
170 | color: inherit;
171 | }
172 |
173 |
174 |
177 |
181 |
182 | `;
183 |
184 | exports[`Support placeholder on the root 1`] = `
185 | .c0::-webkit-input-placeholder {
186 | color: #98a3b3;
187 | }
188 |
189 | .c0::-moz-placeholder {
190 | color: #98a3b3;
191 | }
192 |
193 | .c0:-ms-input-placeholder {
194 | color: #98a3b3;
195 | }
196 |
197 | .c0::placeholder {
198 | color: #98a3b3;
199 | }
200 |
201 |
204 | `;
205 |
206 | exports[`Support styling other components 1`] = `
207 | .c2 {
208 | color: brown;
209 | }
210 |
211 | .c4 {
212 | color: red;
213 | }
214 |
215 | .c0 .c1,
216 | .c0 .c3 {
217 | width: 400px;
218 | }
219 |
220 |
230 | `;
231 |
232 | exports[`Support the styled-components css 1`] = `
233 | .c0 {
234 | padding: 1rem;
235 | }
236 |
237 |
240 | `;
241 |
242 | exports[`Support the styled-components css 2`] = `
243 | .c0 {
244 | padding: 1rem;
245 | border: 1px solid red;
246 | }
247 |
248 |
251 | `;
252 |
253 | exports[`Support the styled-components syntax 1`] = `
254 | .c0 {
255 | width: 400px;
256 | width: 400px;
257 | border: 1px solid #000;
258 | border: 1px solid #000;
259 | background: palevioletred;
260 | color: white;
261 | color2: #5cb85c;
262 | color3: red;
263 | box-shadow: inset 0 0 0 30px rgba(255,255,255,0.3);
264 | }
265 |
266 |
270 | `;
271 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Type.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Returns true if a value is a color, false otherwise. 1`] = `
4 | .c0 {
5 | v1: true;
6 | v2: true;
7 | v3: false;
8 | v4: false;
9 | v5: false;
10 | v6: false;
11 | v7: false;
12 | v8: false;
13 | }
14 |
15 |
18 | `;
19 |
20 | exports[`Returns true if a value is a color, false otherwise. 2`] = `
21 | .c0 {
22 | v1: true;
23 | v2: true;
24 | v3: false;
25 | v4: false;
26 | v5: false;
27 | v6: false;
28 | v7: false;
29 | v8: false;
30 | }
31 |
32 |
35 | `;
36 |
37 | exports[`Returns true if a value is a number in pixels, false otherwise. 1`] = `
38 | .c0 {
39 | is: true;
40 | }
41 |
42 |
45 | `;
46 |
47 | exports[`Returns true if a value is a number in pixels, false otherwise. 2`] = `
48 | .c0 {
49 | is: true;
50 | }
51 |
52 |
55 | `;
56 |
57 | exports[`Returns true if a value is a number, false otherwise. 1`] = `
58 | .c0 {
59 | number1: false;
60 | number2: false;
61 | number3: false;
62 | number4: true;
63 | number5: true;
64 | number6: true;
65 | number7: false;
66 | number8: false;
67 | }
68 |
69 |
72 | `;
73 |
74 | exports[`Returns true if a value is a number, false otherwise. 2`] = `
75 | .c0 {
76 | number1: false;
77 | number2: false;
78 | number3: false;
79 | number4: true;
80 | number5: true;
81 | number6: true;
82 | number7: false;
83 | number8: false;
84 | }
85 |
86 |
89 | `;
90 |
91 | exports[`Returns true if a value is a string, false otherwise. 1`] = `
92 | .c0 {
93 | string1: false;
94 | string2: false;
95 | string3: true;
96 | string4: false;
97 | string5: false;
98 | string6: false;
99 | string7: false;
100 | string8: false;
101 | }
102 |
103 |
106 | `;
107 |
108 | exports[`Returns true if a value is a string, false otherwise. 2`] = `
109 | .c0 {
110 | string1: false;
111 | string2: false;
112 | string3: true;
113 | string4: false;
114 | string5: false;
115 | string6: false;
116 | string7: false;
117 | string1: false;
118 | }
119 |
120 |
123 | `;
124 |
125 | exports[`Returns true if a value is an em value, false otherwise. 1`] = `
126 | .c0 {
127 | is: true;
128 | }
129 |
130 |
133 | `;
134 |
135 | exports[`Returns true if a value is an em value, false otherwise. 2`] = `
136 | .c0 {
137 | is: true;
138 | }
139 |
140 |
143 | `;
144 |
145 | exports[`Returns: true if value is a number in specific units, false otherwise. 1`] = `
146 | .c0 {
147 | is: true;
148 | }
149 |
150 |
153 | `;
154 |
155 | exports[`Returns: true if value is a number in specific units, false otherwise. 2`] = `
156 | .c0 {
157 | is: false;
158 | width: 7.8%;
159 | }
160 |
161 |
164 | `;
165 |
166 | exports[`Returns: true if value is a percentage value, false otherwise. 1`] = `
167 | .c0 {
168 | is: true;
169 | }
170 |
171 |
174 | `;
175 |
176 | exports[`Returns: true if value is a percentage value, false otherwise. 2`] = `
177 | .c0 {
178 | is: true;
179 | }
180 |
181 |
184 | `;
185 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/Variable.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`#32, Fail to escape variable with string and variable 1`] = `
4 | .c0 {
5 | font-family: "Monospaced Number","Chinese Quote",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","Helvetica Neue",Helvetica,Arial,sans-serif;
6 | }
7 |
8 |
11 | `;
12 |
13 | exports[`#32, Fail to escape variable with string and variable from import 1`] = `
14 | .c0 {
15 | font-family: "Monospaced Number less","Chinese Quote",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","Helvetica Neue",Helvetica,Arial,sans-serif;
16 | }
17 |
18 |
21 | `;
22 |
23 | exports[`#32, Fail to escape variable with string and variable from import 2`] = `
24 | .c0 {
25 | font-family: "Monospaced Number less",font-family-no-number;
26 | }
27 |
28 |
31 | `;
32 |
33 | exports[`#34 1`] = `
34 | .c0.ant-btn {
35 | font-size: 3.2rem;
36 | font-weight: 700;
37 | width: 40px;
38 | -webkit-text-decoration: none;
39 | text-decoration: none;
40 | }
41 |
42 | .c0.ant-btn,
43 | .c0.ant-btn:hover,
44 | .c0.ant-btn:focus,
45 | .c0.ant-btn:active,
46 | .c0.ant-btn.active {
47 | background: none;
48 | border-color: transparent;
49 | }
50 |
51 | .c1.c1 {
52 | width: auto;
53 | }
54 |
55 |
58 | `;
59 |
60 | exports[`#34 2`] = `
61 | .c0.ant-btn {
62 | font-size: 3.2rem;
63 | font-weight: 700;
64 | width: 40px;
65 | -webkit-text-decoration: none;
66 | text-decoration: none;
67 | padding: 1rem;
68 | }
69 |
70 | .c0.ant-btn,
71 | .c0.ant-btn:hover,
72 | .c0.ant-btn:focus,
73 | .c0.ant-btn:active,
74 | .c0.ant-btn.active {
75 | background: none;
76 | border-color: transparent;
77 | }
78 |
79 | .c1.c1 {
80 | width: 100%;
81 | }
82 |
83 |
86 | `;
87 |
88 | exports[`Nested variables 1`] = `
89 | .c0 {
90 | font-family: "root","Monospaced","Number","Third";
91 | }
92 |
93 |
96 | `;
97 |
98 | exports[`Nested variables 2`] = `
99 | .c0 {
100 | font-family: "root","Monospaced","Number",Arial;
101 | }
102 |
103 |
106 | `;
107 |
108 | exports[`Replaces single variable in linear-gradient 1`] = `
109 | .c0 {
110 | background: linear-gradient(red 0%,blue 100%);
111 | }
112 |
113 |
118 | `;
119 |
120 | exports[`Takes the color from props 1`] = `
121 | .c0 {
122 | background-color: chocolate;
123 | color: red;
124 | }
125 |
126 |
129 | `;
130 |
131 | exports[`Use the color defiened in the component 1`] = `
132 | .c0 {
133 | color: palevioletred;
134 | }
135 |
136 |
139 | `;
140 |
--------------------------------------------------------------------------------
/test/Component/__snapshots__/createGlobalStyle.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Should theme the global style 1`] = `
4 | "
5 | /* sc-component-id: sc-global-2534925725 */
6 | html{color:color;}"
7 | `;
8 |
--------------------------------------------------------------------------------
/test/Component/base.less:
--------------------------------------------------------------------------------
1 | @base-color: #b5483d;
2 | .base-mixin {
3 | background: #39688f;
4 | }
--------------------------------------------------------------------------------
/test/Component/color/bezierEasing.less:
--------------------------------------------------------------------------------
1 | /* stylelint-disable declaration-bang-space-before,no-duplicate-selectors */
2 | .bezierEasingMixin() {
3 | @functions: ~`(function() {
4 | var NEWTON_ITERATIONS = 4;
5 | var NEWTON_MIN_SLOPE = 0.001;
6 | var SUBDIVISION_PRECISION = 0.0000001;
7 | var SUBDIVISION_MAX_ITERATIONS = 10;
8 |
9 | var kSplineTableSize = 11;
10 | var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
11 |
12 | var float32ArraySupported = typeof Float32Array === 'function';
13 |
14 | function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
15 | function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
16 | function C (aA1) { return 3.0 * aA1; }
17 |
18 | // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
19 | function calcBezier (aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; }
20 |
21 | // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
22 | function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); }
23 |
24 | function binarySubdivide (aX, aA, aB, mX1, mX2) {
25 | var currentX, currentT, i = 0;
26 | do {
27 | currentT = aA + (aB - aA) / 2.0;
28 | currentX = calcBezier(currentT, mX1, mX2) - aX;
29 | if (currentX > 0.0) {
30 | aB = currentT;
31 | } else {
32 | aA = currentT;
33 | }
34 | } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
35 | return currentT;
36 | }
37 |
38 | function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) {
39 | for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
40 | var currentSlope = getSlope(aGuessT, mX1, mX2);
41 | if (currentSlope === 0.0) {
42 | return aGuessT;
43 | }
44 | var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
45 | aGuessT -= currentX / currentSlope;
46 | }
47 | return aGuessT;
48 | }
49 |
50 | var BezierEasing = function (mX1, mY1, mX2, mY2) {
51 | if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) {
52 | throw new Error('bezier x values must be in [0, 1] range');
53 | }
54 |
55 | // Precompute samples table
56 | var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
57 | if (mX1 !== mY1 || mX2 !== mY2) {
58 | for (var i = 0; i < kSplineTableSize; ++i) {
59 | sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
60 | }
61 | }
62 |
63 | function getTForX (aX) {
64 | var intervalStart = 0.0;
65 | var currentSample = 1;
66 | var lastSample = kSplineTableSize - 1;
67 |
68 | for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {
69 | intervalStart += kSampleStepSize;
70 | }
71 | --currentSample;
72 |
73 | // Interpolate to provide an initial guess for t
74 | var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
75 | var guessForT = intervalStart + dist * kSampleStepSize;
76 |
77 | var initialSlope = getSlope(guessForT, mX1, mX2);
78 | if (initialSlope >= NEWTON_MIN_SLOPE) {
79 | return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
80 | } else if (initialSlope === 0.0) {
81 | return guessForT;
82 | } else {
83 | return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
84 | }
85 | }
86 |
87 | return function BezierEasing (x) {
88 | if (mX1 === mY1 && mX2 === mY2) {
89 | return x; // linear
90 | }
91 | // Because JavaScript number are imprecise, we should guarantee the extremes are right.
92 | if (x === 0) {
93 | return 0;
94 | }
95 | if (x === 1) {
96 | return 1;
97 | }
98 | return calcBezier(getTForX(x), mY1, mY2);
99 | };
100 | };
101 |
102 | this.colorEasing = BezierEasing(0.26, 0.09, 0.37, 0.18);
103 | // less 3 requires a return
104 | return '';
105 | })()`;
106 | }
107 | // It is hacky way to make this function will be compiled preferentially by less
108 | // resolve error: `ReferenceError: colorPalette is not defined`
109 | // https://github.com/ant-design/ant-motion/issues/44
110 | .bezierEasingMixin();
111 |
--------------------------------------------------------------------------------
/test/Component/color/colorPalette.less:
--------------------------------------------------------------------------------
1 | /* stylelint-disable no-duplicate-selectors */
2 | @import "bezierEasing";
3 | @import "tinyColor";
4 |
5 | // We create a very complex algorithm which take the place of original tint/shade color system
6 | // to make sure no one can understand it 👻
7 | // and create an entire color palette magicly by inputing just a single primary color.
8 | // We are using bezier-curve easing function and some color manipulations like tint/shade/darken/spin
9 | .colorPaletteMixin() {
10 | @functions: ~`(function() {
11 | var hueStep = 2;
12 | var saturationStep = 16;
13 | var saturationStep2 = 5;
14 | var brightnessStep1 = 5;
15 | var brightnessStep2 = 15;
16 | var lightColorCount = 5;
17 | var darkColorCount = 4;
18 |
19 | var getHue = function(hsv, i, isLight) {
20 | var hue;
21 | if (hsv.h >= 60 && hsv.h <= 240) {
22 | hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i;
23 | } else {
24 | hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i;
25 | }
26 | if (hue < 0) {
27 | hue += 360;
28 | } else if (hue >= 360) {
29 | hue -= 360;
30 | }
31 | return Math.round(hue);
32 | };
33 | var getSaturation = function(hsv, i, isLight) {
34 | var saturation;
35 | if (isLight) {
36 | saturation = Math.round(hsv.s * 100) - saturationStep * i;
37 | } else if (i == darkColorCount) {
38 | saturation = Math.round(hsv.s * 100) + saturationStep;
39 | } else {
40 | saturation = Math.round(hsv.s * 100) + saturationStep2 * i;
41 | }
42 | if (saturation > 100) {
43 | saturation = 100;
44 | }
45 | if (isLight && i === lightColorCount && saturation > 10) {
46 | saturation = 10;
47 | }
48 | if (saturation < 6) {
49 | saturation = 6;
50 | }
51 | return Math.round(saturation);
52 | };
53 | var getValue = function(hsv, i, isLight) {
54 | if (isLight) {
55 | return Math.round(hsv.v * 100) + brightnessStep1 * i;
56 | }
57 | return Math.round(hsv.v * 100) - brightnessStep2 * i;
58 | };
59 |
60 | this.colorPalette = function(color, index) {
61 | var isLight = index <= 6;
62 | var hsv = tinycolor(color).toHsv();
63 | var i = isLight ? lightColorCount + 1 - index : index - lightColorCount - 1;
64 | return tinycolor({
65 | h: getHue(hsv, i, isLight),
66 | s: getSaturation(hsv, i, isLight),
67 | v: getValue(hsv, i, isLight),
68 | }).toHexString();
69 | };
70 | })()`;
71 | }
72 | // It is hacky way to make this function will be compiled preferentially by less
73 | // resolve error: `ReferenceError: colorPalette is not defined`
74 | // https://github.com/ant-design/ant-motion/issues/44
75 | .colorPaletteMixin();
76 |
--------------------------------------------------------------------------------
/test/Component/color/tinyColor.less:
--------------------------------------------------------------------------------
1 | /* stylelint-disable declaration-bang-space-before,no-duplicate-selectors,string-no-newline */
2 | .tinyColorMixin() {
3 | @functions: ~`(function() {
4 | // TinyColor v1.4.1
5 | // https://github.com/bgrins/TinyColor
6 | // 2016-07-07, Brian Grinstead, MIT License
7 | var trimLeft = /^\s+/,
8 | trimRight = /\s+$/,
9 | tinyCounter = 0,
10 | mathRound = Math.round,
11 | mathMin = Math.min,
12 | mathMax = Math.max;
13 |
14 | function tinycolor (color, opts) {
15 |
16 | color = (color) ? color : '';
17 | opts = opts || { };
18 |
19 | // If input is already a tinycolor, return itself
20 | if (color instanceof tinycolor) {
21 | return color;
22 | }
23 | // If we are called as a function, call using new instead
24 | if (!(this instanceof tinycolor)) {
25 | return new tinycolor(color, opts);
26 | }
27 |
28 | var rgb = inputToRGB(color);
29 | this._originalInput = color,
30 | this._r = rgb.r,
31 | this._g = rgb.g,
32 | this._b = rgb.b,
33 | this._a = rgb.a,
34 | this._roundA = mathRound(100*this._a) / 100,
35 | this._format = opts.format || rgb.format;
36 | this._gradientType = opts.gradientType;
37 |
38 | // Don't let the range of [0,255] come back in [0,1].
39 | // Potentially lose a little bit of precision here, but will fix issues where
40 | // .5 gets interpreted as half of the total, instead of half of 1
41 | // If it was supposed to be 128, this was already taken care of by inputToRgb
42 | if (this._r < 1) { this._r = mathRound(this._r); }
43 | if (this._g < 1) { this._g = mathRound(this._g); }
44 | if (this._b < 1) { this._b = mathRound(this._b); }
45 |
46 | this._ok = rgb.ok;
47 | this._tc_id = tinyCounter++;
48 | }
49 |
50 | tinycolor.prototype = {
51 | toHsv: function() {
52 | var hsv = rgbToHsv(this._r, this._g, this._b);
53 | return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
54 | },
55 | toHex: function(allow3Char) {
56 | return rgbToHex(this._r, this._g, this._b, allow3Char);
57 | },
58 | toHexString: function(allow3Char) {
59 | return '#' + this.toHex(allow3Char);
60 | }
61 | };
62 |
63 | // rgbToHsv
64 | // Converts an RGB color value to HSV
65 | // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
66 | // *Returns:* { h, s, v } in [0,1]
67 | function rgbToHsv(r, g, b) {
68 |
69 | r = bound01(r, 255);
70 | g = bound01(g, 255);
71 | b = bound01(b, 255);
72 |
73 | var max = mathMax(r, g, b), min = mathMin(r, g, b);
74 | var h, s, v = max;
75 |
76 | var d = max - min;
77 | s = max === 0 ? 0 : d / max;
78 |
79 | if(max == min) {
80 | h = 0; // achromatic
81 | }
82 | else {
83 | switch(max) {
84 | case r: h = (g - b) / d + (g < b ? 6 : 0); break;
85 | case g: h = (b - r) / d + 2; break;
86 | case b: h = (r - g) / d + 4; break;
87 | }
88 | h /= 6;
89 | }
90 | return { h: h, s: s, v: v };
91 | }
92 |
93 | // rgbToHex
94 | // Converts an RGB color to hex
95 | // Assumes r, g, and b are contained in the set [0, 255]
96 | // Returns a 3 or 6 character hex
97 | function rgbToHex(r, g, b, allow3Char) {
98 |
99 | var hex = [
100 | pad2(mathRound(r).toString(16)),
101 | pad2(mathRound(g).toString(16)),
102 | pad2(mathRound(b).toString(16))
103 | ];
104 |
105 | // Return a 3 character hex if possible
106 | if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
107 | return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
108 | }
109 |
110 | return hex.join("");
111 | }
112 |
113 |
114 | // Take input from [0, n] and return it as [0, 1]
115 | function bound01(n, max) {
116 | if (isOnePointZero(n)) { n = "100%"; }
117 |
118 | var processPercent = isPercentage(n);
119 | n = mathMin(max, mathMax(0, parseFloat(n)));
120 |
121 | // Automatically convert percentage into number
122 | if (processPercent) {
123 | n = parseInt(n * max, 10) / 100;
124 | }
125 |
126 | // Handle floating point rounding errors
127 | if ((Math.abs(n - max) < 0.000001)) {
128 | return 1;
129 | }
130 |
131 | // Convert into [0, 1] range if it isn't already
132 | return (n % max) / parseFloat(max);
133 | }
134 |
135 | // Given a string or object, convert that input to RGB
136 | // Possible string inputs:
137 | //
138 | // "red"
139 | // "#f00" or "f00"
140 | // "#ff0000" or "ff0000"
141 | // "#ff000000" or "ff000000"
142 | // "rgb 255 0 0" or "rgb (255, 0, 0)"
143 | // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
144 | // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
145 | // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
146 | // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
147 | // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
148 | // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
149 | //
150 | function inputToRGB(color) {
151 |
152 | var rgb = { r: 0, g: 0, b: 0 };
153 | var a = 1;
154 | var s = null;
155 | var v = null;
156 | var l = null;
157 | var ok = false;
158 | var format = false;
159 |
160 | if (typeof color == "string") {
161 | color = stringInputToObject(color);
162 | }
163 |
164 | if (typeof color == "object") {
165 | if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
166 | rgb = rgbToRgb(color.r, color.g, color.b);
167 | ok = true;
168 | format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
169 | }
170 | else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
171 | s = convertToPercentage(color.s);
172 | v = convertToPercentage(color.v);
173 | rgb = hsvToRgb(color.h, s, v);
174 | ok = true;
175 | format = "hsv";
176 | }
177 | else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
178 | s = convertToPercentage(color.s);
179 | l = convertToPercentage(color.l);
180 | rgb = hslToRgb(color.h, s, l);
181 | ok = true;
182 | format = "hsl";
183 | }
184 |
185 | if (color.hasOwnProperty("a")) {
186 | a = color.a;
187 | }
188 | }
189 |
190 | a = boundAlpha(a);
191 |
192 | return {
193 | ok: ok,
194 | format: color.format || format,
195 | r: mathMin(255, mathMax(rgb.r, 0)),
196 | g: mathMin(255, mathMax(rgb.g, 0)),
197 | b: mathMin(255, mathMax(rgb.b, 0)),
198 | a: a
199 | };
200 | }
201 |
202 | // Conversion Functions
203 | // --------------------
204 |
205 | // rgbToHsl, rgbToHsv, hslToRgb, hsvToRgb modified from:
206 | //
207 |
208 | // rgbToRgb
209 | // Handle bounds / percentage checking to conform to CSS color spec
210 | //
211 | // *Assumes:* r, g, b in [0, 255] or [0, 1]
212 | // *Returns:* { r, g, b } in [0, 255]
213 | function rgbToRgb(r, g, b){
214 | return {
215 | r: bound01(r, 255) * 255,
216 | g: bound01(g, 255) * 255,
217 | b: bound01(b, 255) * 255
218 | };
219 | }
220 |
221 | // hslToRgb
222 | // Converts an HSL color value to RGB.
223 | // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
224 | // *Returns:* { r, g, b } in the set [0, 255]
225 | function hslToRgb(h, s, l) {
226 | var r, g, b;
227 |
228 | h = bound01(h, 360);
229 | s = bound01(s, 100);
230 | l = bound01(l, 100);
231 |
232 | function hue2rgb(p, q, t) {
233 | if(t < 0) t += 1;
234 | if(t > 1) t -= 1;
235 | if(t < 1/6) return p + (q - p) * 6 * t;
236 | if(t < 1/2) return q;
237 | if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
238 | return p;
239 | }
240 |
241 | if(s === 0) {
242 | r = g = b = l; // achromatic
243 | }
244 | else {
245 | var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
246 | var p = 2 * l - q;
247 | r = hue2rgb(p, q, h + 1/3);
248 | g = hue2rgb(p, q, h);
249 | b = hue2rgb(p, q, h - 1/3);
250 | }
251 |
252 | return { r: r * 255, g: g * 255, b: b * 255 };
253 | }
254 |
255 | // hsvToRgb
256 | // Converts an HSV color value to RGB.
257 | // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
258 | // *Returns:* { r, g, b } in the set [0, 255]
259 | function hsvToRgb(h, s, v) {
260 |
261 | h = bound01(h, 360) * 6;
262 | s = bound01(s, 100);
263 | v = bound01(v, 100);
264 |
265 | var i = Math.floor(h),
266 | f = h - i,
267 | p = v * (1 - s),
268 | q = v * (1 - f * s),
269 | t = v * (1 - (1 - f) * s),
270 | mod = i % 6,
271 | r = [v, q, p, p, t, v][mod],
272 | g = [t, v, v, q, p, p][mod],
273 | b = [p, p, t, v, v, q][mod];
274 |
275 | return { r: r * 255, g: g * 255, b: b * 255 };
276 | }
277 |
278 | // Big List of Colors
279 | // ------------------
280 | //
281 | var names = tinycolor.names = {
282 | aliceblue: "f0f8ff",
283 | antiquewhite: "faebd7",
284 | aqua: "0ff",
285 | aquamarine: "7fffd4",
286 | azure: "f0ffff",
287 | beige: "f5f5dc",
288 | bisque: "ffe4c4",
289 | black: "000",
290 | blanchedalmond: "ffebcd",
291 | blue: "00f",
292 | blueviolet: "8a2be2",
293 | brown: "a52a2a",
294 | burlywood: "deb887",
295 | burntsienna: "ea7e5d",
296 | cadetblue: "5f9ea0",
297 | chartreuse: "7fff00",
298 | chocolate: "d2691e",
299 | coral: "ff7f50",
300 | cornflowerblue: "6495ed",
301 | cornsilk: "fff8dc",
302 | crimson: "dc143c",
303 | cyan: "0ff",
304 | darkblue: "00008b",
305 | darkcyan: "008b8b",
306 | darkgoldenrod: "b8860b",
307 | darkgray: "a9a9a9",
308 | darkgreen: "006400",
309 | darkgrey: "a9a9a9",
310 | darkkhaki: "bdb76b",
311 | darkmagenta: "8b008b",
312 | darkolivegreen: "556b2f",
313 | darkorange: "ff8c00",
314 | darkorchid: "9932cc",
315 | darkred: "8b0000",
316 | darksalmon: "e9967a",
317 | darkseagreen: "8fbc8f",
318 | darkslateblue: "483d8b",
319 | darkslategray: "2f4f4f",
320 | darkslategrey: "2f4f4f",
321 | darkturquoise: "00ced1",
322 | darkviolet: "9400d3",
323 | deeppink: "ff1493",
324 | deepskyblue: "00bfff",
325 | dimgray: "696969",
326 | dimgrey: "696969",
327 | dodgerblue: "1e90ff",
328 | firebrick: "b22222",
329 | floralwhite: "fffaf0",
330 | forestgreen: "228b22",
331 | fuchsia: "f0f",
332 | gainsboro: "dcdcdc",
333 | ghostwhite: "f8f8ff",
334 | gold: "ffd700",
335 | goldenrod: "daa520",
336 | gray: "808080",
337 | green: "008000",
338 | greenyellow: "adff2f",
339 | grey: "808080",
340 | honeydew: "f0fff0",
341 | hotpink: "ff69b4",
342 | indianred: "cd5c5c",
343 | indigo: "4b0082",
344 | ivory: "fffff0",
345 | khaki: "f0e68c",
346 | lavender: "e6e6fa",
347 | lavenderblush: "fff0f5",
348 | lawngreen: "7cfc00",
349 | lemonchiffon: "fffacd",
350 | lightblue: "add8e6",
351 | lightcoral: "f08080",
352 | lightcyan: "e0ffff",
353 | lightgoldenrodyellow: "fafad2",
354 | lightgray: "d3d3d3",
355 | lightgreen: "90ee90",
356 | lightgrey: "d3d3d3",
357 | lightpink: "ffb6c1",
358 | lightsalmon: "ffa07a",
359 | lightseagreen: "20b2aa",
360 | lightskyblue: "87cefa",
361 | lightslategray: "789",
362 | lightslategrey: "789",
363 | lightsteelblue: "b0c4de",
364 | lightyellow: "ffffe0",
365 | lime: "0f0",
366 | limegreen: "32cd32",
367 | linen: "faf0e6",
368 | magenta: "f0f",
369 | maroon: "800000",
370 | mediumaquamarine: "66cdaa",
371 | mediumblue: "0000cd",
372 | mediumorchid: "ba55d3",
373 | mediumpurple: "9370db",
374 | mediumseagreen: "3cb371",
375 | mediumslateblue: "7b68ee",
376 | mediumspringgreen: "00fa9a",
377 | mediumturquoise: "48d1cc",
378 | mediumvioletred: "c71585",
379 | midnightblue: "191970",
380 | mintcream: "f5fffa",
381 | mistyrose: "ffe4e1",
382 | moccasin: "ffe4b5",
383 | navajowhite: "ffdead",
384 | navy: "000080",
385 | oldlace: "fdf5e6",
386 | olive: "808000",
387 | olivedrab: "6b8e23",
388 | orange: "ffa500",
389 | orangered: "ff4500",
390 | orchid: "da70d6",
391 | palegoldenrod: "eee8aa",
392 | palegreen: "98fb98",
393 | paleturquoise: "afeeee",
394 | palevioletred: "db7093",
395 | papayawhip: "ffefd5",
396 | peachpuff: "ffdab9",
397 | peru: "cd853f",
398 | pink: "ffc0cb",
399 | plum: "dda0dd",
400 | powderblue: "b0e0e6",
401 | purple: "800080",
402 | rebeccapurple: "663399",
403 | red: "f00",
404 | rosybrown: "bc8f8f",
405 | royalblue: "4169e1",
406 | saddlebrown: "8b4513",
407 | salmon: "fa8072",
408 | sandybrown: "f4a460",
409 | seagreen: "2e8b57",
410 | seashell: "fff5ee",
411 | sienna: "a0522d",
412 | silver: "c0c0c0",
413 | skyblue: "87ceeb",
414 | slateblue: "6a5acd",
415 | slategray: "708090",
416 | slategrey: "708090",
417 | snow: "fffafa",
418 | springgreen: "00ff7f",
419 | steelblue: "4682b4",
420 | tan: "d2b48c",
421 | teal: "008080",
422 | thistle: "d8bfd8",
423 | tomato: "ff6347",
424 | turquoise: "40e0d0",
425 | violet: "ee82ee",
426 | wheat: "f5deb3",
427 | white: "fff",
428 | whitesmoke: "f5f5f5",
429 | yellow: "ff0",
430 | yellowgreen: "9acd32"
431 | };
432 |
433 | // Utilities
434 | // ---------
435 |
436 | // Return a valid alpha value [0,1] with all invalid values being set to 1
437 | function boundAlpha(a) {
438 | a = parseFloat(a);
439 |
440 | if (isNaN(a) || a < 0 || a > 1) {
441 | a = 1;
442 | }
443 |
444 | return a;
445 | }
446 |
447 | // Parse a base-16 hex value into a base-10 integer
448 | function parseIntFromHex(val) {
449 | return parseInt(val, 16);
450 | }
451 |
452 | // Converts a hex value to a decimal
453 | function convertHexToDecimal(h) {
454 | return (parseIntFromHex(h) / 255);
455 | }
456 |
457 | // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
458 | //
459 | function isOnePointZero(n) {
460 | return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
461 | }
462 |
463 | // Check to see if string passed in is a percentage
464 | function isPercentage(n) {
465 | return typeof n === "string" && n.indexOf('%') != -1;
466 | }
467 |
468 | // Force a hex value to have 2 characters
469 | function pad2(c) {
470 | return c.length == 1 ? '0' + c : '' + c;
471 | }
472 |
473 | // Replace a decimal with it's percentage value
474 | function convertToPercentage(n) {
475 | if (n <= 1) {
476 | n = (n * 100) + "%";
477 | }
478 |
479 | return n;
480 | }
481 |
482 | var matchers = (function() {
483 |
484 | //
485 | var CSS_INTEGER = "[-\\+]?\\d+%?";
486 |
487 | //
488 | var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
489 |
490 | // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
491 | var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
492 |
493 | // Actual matching.
494 | // Parentheses and commas are optional, but not required.
495 | // Whitespace can take the place of commas or opening paren
496 | var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
497 | var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
498 |
499 | return {
500 | CSS_UNIT: new RegExp(CSS_UNIT),
501 | rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
502 | rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
503 | hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
504 | hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
505 | hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
506 | hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
507 | hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
508 | hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
509 | hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
510 | hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
511 | };
512 | })();
513 |
514 | // isValidCSSUnit
515 | // Take in a single string / number and check to see if it looks like a CSS unit
516 | // (see matchers above for definition).
517 | function isValidCSSUnit(color) {
518 | return !!matchers.CSS_UNIT.exec(color);
519 | }
520 |
521 | // stringInputToObject
522 | // Permissive string parsing. Take in a number of formats, and output an object
523 | // based on detected format. Returns { r, g, b } or { h, s, l } or { h, s, v}
524 | function stringInputToObject(color) {
525 |
526 | color = color.replace(trimLeft, '').replace(trimRight, '').toLowerCase();
527 | var named = false;
528 | if (names[color]) {
529 | color = names[color];
530 | named = true;
531 | }
532 | else if (color == 'transparent') {
533 | return { r: 0, g: 0, b: 0, a: 0, format: "name" };
534 | }
535 |
536 | // Try to match string input using regular expressions.
537 | // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
538 | // Just return an object and let the conversion functions handle that.
539 | // This way the result will be the same whether the tinycolor is initialized with string or object.
540 | var match;
541 | /* eslint-disable no-cond-assign */
542 | if ((match = matchers.rgb.exec(color))) {
543 | return { r: match[1], g: match[2], b: match[3] };
544 | }
545 | if ((match = matchers.rgba.exec(color))) {
546 | return { r: match[1], g: match[2], b: match[3], a: match[4] };
547 | }
548 | if ((match = matchers.hsl.exec(color))) {
549 | return { h: match[1], s: match[2], l: match[3] };
550 | }
551 | if ((match = matchers.hsla.exec(color))) {
552 | return { h: match[1], s: match[2], l: match[3], a: match[4] };
553 | }
554 | if ((match = matchers.hsv.exec(color))) {
555 | return { h: match[1], s: match[2], v: match[3] };
556 | }
557 | if ((match = matchers.hsva.exec(color))) {
558 | return { h: match[1], s: match[2], v: match[3], a: match[4] };
559 | }
560 | if ((match = matchers.hex8.exec(color))) {
561 | return {
562 | r: parseIntFromHex(match[1]),
563 | g: parseIntFromHex(match[2]),
564 | b: parseIntFromHex(match[3]),
565 | a: convertHexToDecimal(match[4]),
566 | format: named ? "name" : "hex8"
567 | };
568 | }
569 | if ((match = matchers.hex6.exec(color))) {
570 | return {
571 | r: parseIntFromHex(match[1]),
572 | g: parseIntFromHex(match[2]),
573 | b: parseIntFromHex(match[3]),
574 | format: named ? "name" : "hex"
575 | };
576 | }
577 | if ((match = matchers.hex4.exec(color))) {
578 | return {
579 | r: parseIntFromHex(match[1] + '' + match[1]),
580 | g: parseIntFromHex(match[2] + '' + match[2]),
581 | b: parseIntFromHex(match[3] + '' + match[3]),
582 | a: convertHexToDecimal(match[4] + '' + match[4]),
583 | format: named ? "name" : "hex8"
584 | };
585 | }
586 | if ((match = matchers.hex3.exec(color))) {
587 | return {
588 | r: parseIntFromHex(match[1] + '' + match[1]),
589 | g: parseIntFromHex(match[2] + '' + match[2]),
590 | b: parseIntFromHex(match[3] + '' + match[3]),
591 | format: named ? "name" : "hex"
592 | };
593 | }
594 | /* eslint-enable no-cond-assign */
595 |
596 | return false;
597 | }
598 |
599 | this.tinycolor = tinycolor;
600 |
601 | })()`;
602 | }
603 | // It is hacky way to make this function will be compiled preferentially by less
604 | // resolve error: `ReferenceError: colorPalette is not defined`
605 | // https://github.com/ant-design/ant-motion/issues/44
606 | .tinyColorMixin();
607 |
--------------------------------------------------------------------------------
/test/Component/createGlobalStyle.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import renderer from 'react-test-renderer';
3 | import {createGlobalStyle} from 'styled-components';
4 | import 'jest-styled-components';
5 |
6 | export const getCSS = scope => Array.from(scope.querySelectorAll('style')).map(tag => tag.innerHTML).join('\n');
7 |
8 | test('Should theme the global style', () => {
9 | const GlobalStyle = createGlobalStyle`
10 | html {
11 | color: @color;
12 | }
13 | `;
14 | renderer.create();
15 | expect(getCSS(document)).toMatchSnapshot();
16 | });
--------------------------------------------------------------------------------
/test/Component/echoColor.less:
--------------------------------------------------------------------------------
1 | /* stylelint-disable declaration-bang-space-before,no-duplicate-selectors */
2 |
3 | .echoColorMixin() {
4 | @functions: ~`(function() {
5 | this.echoColor = function(color, index) {
6 | return color;
7 | }
8 | }
9 | )()`;
10 | }
11 |
12 | // It is hacky way to make this function will be compiled preferentially by less
13 | .echoColorMixin();
14 |
--------------------------------------------------------------------------------
/test/Component/import-scoped.less:
--------------------------------------------------------------------------------
1 | @import "~@scoped/package/import.less";
--------------------------------------------------------------------------------
/test/Component/import.less:
--------------------------------------------------------------------------------
1 | .foo {
2 | background: #900;
3 | border: 1px solid @color;
4 | }
5 |
6 | @color: green;
7 |
8 | @font-family-no-number: "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
9 | @font-family: "Monospaced Number less", @font-family-no-number;
--------------------------------------------------------------------------------
/test/Component/javascript.less:
--------------------------------------------------------------------------------
1 | /* stylelint-disable declaration-bang-space-before,no-duplicate-selectors */
2 |
3 | .echoColor() {
4 | @functions: ~`(function(colorStr) {
5 | return colorStr;
6 | }
7 | )()`;
8 | }
9 |
10 | // It is hacky way to make this function will be compiled preferentially by less
11 | .echoColor();
12 |
13 |
14 | @import 'color/colorPalette';
15 |
16 | // color palettes
17 | @blue-5: ~`colorPalette("@{blue-6}", 5)`;
18 | @blue-6: #1890ff;
19 |
20 | @primary-color: @blue-6;
21 | @primary-1: ~`colorPalette("@{primary-color}", 1)`;
22 | @primary-2: color(~`colorPalette("@{primary-color}", 1)`);
23 |
--------------------------------------------------------------------------------
/test/packages/scoped-package/import.less:
--------------------------------------------------------------------------------
1 | @foo: yellow;
--------------------------------------------------------------------------------
/test/packages/scoped-package/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@scoped/package",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "license": "MIT"
6 | }
7 |
--------------------------------------------------------------------------------