|
1 | 1 | import postcss from 'postcss'
|
2 | 2 | import plugin from '../src/lib/evaluateTailwindFunctions'
|
| 3 | +import tailwind from '../src/index' |
3 | 4 | import { css } from './util/run'
|
4 | 5 |
|
5 | 6 | function run(input, opts = {}) {
|
6 | 7 | return postcss([plugin({ tailwindConfig: opts })]).process(input, { from: undefined })
|
7 | 8 | }
|
8 | 9 |
|
| 10 | +function runFull(input, config) { |
| 11 | + return postcss([tailwind(config)]).process(input, { from: undefined }) |
| 12 | +} |
| 13 | + |
9 | 14 | test('it looks up values in the theme using dot notation', () => {
|
10 | 15 | let input = css`
|
11 | 16 | .banana {
|
@@ -817,3 +822,205 @@ test('screen arguments can be quoted', () => {
|
817 | 822 | expect(result.warnings().length).toBe(0)
|
818 | 823 | })
|
819 | 824 | })
|
| 825 | + |
| 826 | +test('Theme function can extract alpha values for colors (1)', () => { |
| 827 | + let input = css` |
| 828 | + .foo { |
| 829 | + color: theme(colors.blue.500 / 50%); |
| 830 | + } |
| 831 | + ` |
| 832 | + |
| 833 | + let output = css` |
| 834 | + .foo { |
| 835 | + color: rgb(59 130 246 / 50%); |
| 836 | + } |
| 837 | + ` |
| 838 | + |
| 839 | + return run(input, { |
| 840 | + theme: { |
| 841 | + colors: { blue: { 500: '#3b82f6' } }, |
| 842 | + }, |
| 843 | + }).then((result) => { |
| 844 | + expect(result.css).toMatchCss(output) |
| 845 | + expect(result.warnings().length).toBe(0) |
| 846 | + }) |
| 847 | +}) |
| 848 | + |
| 849 | +test('Theme function can extract alpha values for colors (2)', () => { |
| 850 | + let input = css` |
| 851 | + .foo { |
| 852 | + color: theme(colors.blue.500 / 0.5); |
| 853 | + } |
| 854 | + ` |
| 855 | + |
| 856 | + let output = css` |
| 857 | + .foo { |
| 858 | + color: rgb(59 130 246 / 0.5); |
| 859 | + } |
| 860 | + ` |
| 861 | + |
| 862 | + return run(input, { |
| 863 | + theme: { |
| 864 | + colors: { blue: { 500: '#3b82f6' } }, |
| 865 | + }, |
| 866 | + }).then((result) => { |
| 867 | + expect(result.css).toMatchCss(output) |
| 868 | + expect(result.warnings().length).toBe(0) |
| 869 | + }) |
| 870 | +}) |
| 871 | + |
| 872 | +test('Theme function can extract alpha values for colors (3)', () => { |
| 873 | + let input = css` |
| 874 | + .foo { |
| 875 | + color: theme(colors.blue.500 / var(--my-alpha)); |
| 876 | + } |
| 877 | + ` |
| 878 | + |
| 879 | + let output = css` |
| 880 | + .foo { |
| 881 | + color: rgb(59 130 246 / var(--my-alpha)); |
| 882 | + } |
| 883 | + ` |
| 884 | + |
| 885 | + return run(input, { |
| 886 | + theme: { |
| 887 | + colors: { blue: { 500: '#3b82f6' } }, |
| 888 | + }, |
| 889 | + }).then((result) => { |
| 890 | + expect(result.css).toMatchCss(output) |
| 891 | + expect(result.warnings().length).toBe(0) |
| 892 | + }) |
| 893 | +}) |
| 894 | + |
| 895 | +test('Theme function can extract alpha values for colors (4)', () => { |
| 896 | + let input = css` |
| 897 | + .foo { |
| 898 | + color: theme(colors.blue.500 / 50%); |
| 899 | + } |
| 900 | + ` |
| 901 | + |
| 902 | + let output = css` |
| 903 | + .foo { |
| 904 | + color: hsl(217 91% 60% / 50%); |
| 905 | + } |
| 906 | + ` |
| 907 | + |
| 908 | + return run(input, { |
| 909 | + theme: { |
| 910 | + colors: { |
| 911 | + blue: { 500: 'hsl(217, 91%, 60%)' }, |
| 912 | + }, |
| 913 | + }, |
| 914 | + }).then((result) => { |
| 915 | + expect(result.css).toMatchCss(output) |
| 916 | + expect(result.warnings().length).toBe(0) |
| 917 | + }) |
| 918 | +}) |
| 919 | + |
| 920 | +test('Theme function can extract alpha values for colors (5)', () => { |
| 921 | + let input = css` |
| 922 | + .foo { |
| 923 | + color: theme(colors.blue.500 / 0.5); |
| 924 | + } |
| 925 | + ` |
| 926 | + |
| 927 | + let output = css` |
| 928 | + .foo { |
| 929 | + color: hsl(217 91% 60% / 0.5); |
| 930 | + } |
| 931 | + ` |
| 932 | + |
| 933 | + return run(input, { |
| 934 | + theme: { |
| 935 | + colors: { |
| 936 | + blue: { 500: 'hsl(217, 91%, 60%)' }, |
| 937 | + }, |
| 938 | + }, |
| 939 | + }).then((result) => { |
| 940 | + expect(result.css).toMatchCss(output) |
| 941 | + expect(result.warnings().length).toBe(0) |
| 942 | + }) |
| 943 | +}) |
| 944 | + |
| 945 | +test('Theme function can extract alpha values for colors (6)', () => { |
| 946 | + let input = css` |
| 947 | + .foo { |
| 948 | + color: theme(colors.blue.500 / var(--my-alpha)); |
| 949 | + } |
| 950 | + ` |
| 951 | + |
| 952 | + let output = css` |
| 953 | + .foo { |
| 954 | + color: hsl(217 91% 60% / var(--my-alpha)); |
| 955 | + } |
| 956 | + ` |
| 957 | + |
| 958 | + return run(input, { |
| 959 | + theme: { |
| 960 | + colors: { |
| 961 | + blue: { 500: 'hsl(217, 91%, 60%)' }, |
| 962 | + }, |
| 963 | + }, |
| 964 | + }).then((result) => { |
| 965 | + expect(result.css).toMatchCss(output) |
| 966 | + expect(result.warnings().length).toBe(0) |
| 967 | + }) |
| 968 | +}) |
| 969 | + |
| 970 | +test('Theme function can extract alpha values for colors (7)', () => { |
| 971 | + let input = css` |
| 972 | + .foo { |
| 973 | + color: theme(colors.blue.500 / var(--my-alpha)); |
| 974 | + } |
| 975 | + ` |
| 976 | + |
| 977 | + let output = css` |
| 978 | + .foo { |
| 979 | + color: rgb(var(--foo) / var(--my-alpha)); |
| 980 | + } |
| 981 | + ` |
| 982 | + |
| 983 | + return runFull(input, { |
| 984 | + theme: { |
| 985 | + colors: ({ rgb }) => ({ |
| 986 | + blue: { |
| 987 | + 500: rgb('--foo'), |
| 988 | + }, |
| 989 | + }), |
| 990 | + }, |
| 991 | + }).then((result) => { |
| 992 | + expect(result.css).toMatchCss(output) |
| 993 | + expect(result.warnings().length).toBe(0) |
| 994 | + }) |
| 995 | +}) |
| 996 | + |
| 997 | +test('Theme function can extract alpha values for colors (8)', () => { |
| 998 | + let input = css` |
| 999 | + .foo { |
| 1000 | + color: theme(colors.blue.500 / theme(opacity.myalpha)); |
| 1001 | + } |
| 1002 | + ` |
| 1003 | + |
| 1004 | + let output = css` |
| 1005 | + .foo { |
| 1006 | + color: rgb(var(--foo) / 50%); |
| 1007 | + } |
| 1008 | + ` |
| 1009 | + |
| 1010 | + return runFull(input, { |
| 1011 | + theme: { |
| 1012 | + colors: ({ rgb }) => ({ |
| 1013 | + blue: { |
| 1014 | + 500: rgb('--foo'), |
| 1015 | + }, |
| 1016 | + }), |
| 1017 | + |
| 1018 | + opacity: { |
| 1019 | + myalpha: '50%', |
| 1020 | + }, |
| 1021 | + }, |
| 1022 | + }).then((result) => { |
| 1023 | + expect(result.css).toMatchCss(output) |
| 1024 | + expect(result.warnings().length).toBe(0) |
| 1025 | + }) |
| 1026 | +}) |
0 commit comments