(props?: P) =>
58 | (Pass extends (...args: any) => any ? ReturnType (props?: P) =>
66 | (Pass extends (...args: any) => any ? ReturnType (props?: P) => T | DefaultCase;
74 |
75 | export function withProp (props?: P) => T;
79 |
--------------------------------------------------------------------------------
/test/ifNotProp.test.js:
--------------------------------------------------------------------------------
1 | import ifNotProp from "../src/ifNotProp";
2 |
3 | test("string argument", () => {
4 | expect(ifNotProp("foo", "no", "yes")()).toBe("no");
5 | expect(ifNotProp("foo", "no", "yes")({ foo: true })).toBe("yes");
6 | expect(ifNotProp("foo", "no", "yes")({ foo: false })).toBe("no");
7 | });
8 |
9 | test("deep string argument", () => {
10 | expect(ifNotProp("foo.bar", "no", "yes")({ foo: { bar: true } })).toBe("yes");
11 | expect(ifNotProp("foo.bar", "no", "yes")({ foo: { bar: false } })).toBe("no");
12 | });
13 |
14 | test("array argument", () => {
15 | expect(ifNotProp(["foo"], "no", "yes")({ bar: false, foo: true })).toBe(
16 | "yes"
17 | );
18 | expect(ifNotProp(["foo", "bar"], "no", "yes")({ bar: true, foo: true })).toBe(
19 | "yes"
20 | );
21 | expect(
22 | ifNotProp(["foo", "bar"], "no", "yes")({ foo: true, bar: false })
23 | ).toBe("no");
24 | });
25 |
26 | test("deep array argument", () => {
27 | expect(
28 | ifNotProp(["foo.bar", "baz"], "no", "yes")({
29 | baz: true,
30 | foo: { bar: true }
31 | })
32 | ).toBe("yes");
33 | expect(
34 | ifNotProp(["foo.bar", "baz"], "no", "yes")({
35 | foo: { bar: true },
36 | baz: false
37 | })
38 | ).toBe("no");
39 | expect(
40 | ifNotProp(["foo.bar", "baz"], "no", "yes")({
41 | foo: { bar: false },
42 | baz: true
43 | })
44 | ).toBe("no");
45 | });
46 |
47 | test("object argument", () => {
48 | expect(ifNotProp({ foo: "ok" }, "no", "yes")({ foo: "ok" })).toBe("yes");
49 | expect(ifNotProp({ foo: "ok" }, "no", "yes")({ foo: "not ok" })).toBe("no");
50 | expect(
51 | ifNotProp({ foo: "ok", bar: "ok" }, "no", "yes")({ bar: "ok", foo: "ok" })
52 | ).toBe("yes");
53 | expect(
54 | ifNotProp({ foo: "ok", bar: "ok" }, "no", "yes")({
55 | foo: "not ok",
56 | bar: "ok"
57 | })
58 | ).toBe("no");
59 | });
60 |
61 | test("deep object argument", () => {
62 | expect(
63 | ifNotProp({ "foo.bar": "ok" }, "no", "yes")({ foo: { bar: "ok" } })
64 | ).toBe("yes");
65 | expect(
66 | ifNotProp({ "foo.bar": "ok" }, "no", "yes")({ foo: { bar: "no" } })
67 | ).toBe("no");
68 | });
69 |
70 | test("function argument", () => {
71 | expect(ifNotProp(props => props.foo, "no", "yes")()).toBe("no");
72 | expect(ifNotProp(props => props.foo, "no", "yes")({ foo: false })).toBe("no");
73 | expect(ifNotProp(props => props.foo, "no", "yes")({ foo: true })).toBe("yes");
74 | });
75 |
76 | test("function values", () => {
77 | expect(
78 | ifNotProp("foo", props => props.bar, props => props.foo)({ bar: "bar" })
79 | ).toBe("bar");
80 | expect(
81 | ifNotProp("foo", props => props.bar, props => props.foo)({ foo: "foo" })
82 | ).toBe("foo");
83 | });
84 |
--------------------------------------------------------------------------------
/test/ifProp.test.js:
--------------------------------------------------------------------------------
1 | import ifProp from "../src/ifProp";
2 |
3 | test("no pass/fail", () => {
4 | expect(ifProp("foo")({ foo: true })).toBe("");
5 | });
6 |
7 | test("string argument", () => {
8 | expect(ifProp("foo", "yes", "no")()).toBe("no");
9 | expect(ifProp("foo", "yes", "no")({ foo: true })).toBe("yes");
10 | expect(ifProp("foo", "yes", "no")({ foo: false })).toBe("no");
11 | });
12 |
13 | test("deep string argument", () => {
14 | expect(ifProp("foo.bar", "yes", "no")({ foo: { bar: true } })).toBe("yes");
15 | expect(ifProp("foo.bar", "yes", "no")({ foo: { bar: false } })).toBe("no");
16 | });
17 |
18 | test("array argument", () => {
19 | expect(ifProp(["foo"], "yes", "no")({ bar: false, foo: true })).toBe("yes");
20 | expect(ifProp(["foo", "bar"], "yes", "no")({ bar: true, foo: true })).toBe(
21 | "yes"
22 | );
23 | expect(ifProp(["foo", "bar"], "yes", "no")({ foo: true, bar: false })).toBe(
24 | "no"
25 | );
26 | expect(
27 | ifProp(["foo", "bar"], "yes", () => "no")({ foo: true, bar: false })
28 | ).toBe("no");
29 | });
30 |
31 | test("deep array argument", () => {
32 | expect(
33 | ifProp(["foo.bar", "baz"], "yes", "no")({ baz: true, foo: { bar: true } })
34 | ).toBe("yes");
35 | expect(
36 | ifProp(["foo.bar", "baz"], "yes", "no")({ foo: { bar: true }, baz: false })
37 | ).toBe("no");
38 | expect(
39 | ifProp(["foo.bar", "baz"], "yes", "no")({ foo: { bar: false }, baz: true })
40 | ).toBe("no");
41 | });
42 |
43 | test("function array argument", () => {
44 | expect(
45 | ifProp([props => props.foo], "yes", "no")({ bar: false, foo: true })
46 | ).toBe("yes");
47 | expect(
48 | ifProp(["bar", props => props.foo], "yes", () => "no")({
49 | bar: false,
50 | foo: true
51 | })
52 | ).toBe("no");
53 | });
54 |
55 | test("object array argument", () => {
56 | expect(ifProp([{ foo: true }], "yes", "no")({ bar: false, foo: true })).toBe(
57 | "yes"
58 | );
59 | });
60 |
61 | test("object argument", () => {
62 | expect(ifProp({ foo: "ok" }, "yes", "no")({ foo: "ok" })).toBe("yes");
63 | expect(ifProp({ foo: "ok" }, "yes", "no")({ foo: "not ok" })).toBe("no");
64 | expect(
65 | ifProp({ foo: "ok", bar: "ok" }, "yes", "no")({ bar: "ok", foo: "ok" })
66 | ).toBe("yes");
67 | expect(
68 | ifProp({ foo: "ok", bar: "ok" }, "yes", "no")({ foo: "not ok", bar: "ok" })
69 | ).toBe("no");
70 | });
71 |
72 | test("deep object argument", () => {
73 | expect(ifProp({ "foo.bar": "ok" }, "yes", "no")({ foo: { bar: "ok" } })).toBe(
74 | "yes"
75 | );
76 | expect(ifProp({ "foo.bar": "ok" }, "yes", "no")({ foo: { bar: "no" } })).toBe(
77 | "no"
78 | );
79 | });
80 |
81 | test("function argument", () => {
82 | expect(ifProp(props => props.foo, "yes", "no")()).toBe("no");
83 | expect(ifProp(props => props.foo, "yes", "no")({ foo: false })).toBe("no");
84 | expect(ifProp(props => props.foo, "yes", "no")({ foo: true })).toBe("yes");
85 | });
86 |
87 | test("function values", () => {
88 | expect(
89 | ifProp("foo", props => props.foo, props => props.bar)({ bar: "bar" })
90 | ).toBe("bar");
91 | expect(
92 | ifProp("foo", props => props.foo, props => props.bar)({ foo: "foo" })
93 | ).toBe("foo");
94 | });
95 |
--------------------------------------------------------------------------------
/types/tests.ts:
--------------------------------------------------------------------------------
1 | import { prop, theme, palette, ifProp, ifNotProp, switchProp, withProp } from "..";
2 |
3 | prop("a")({ a: true }) as boolean;
4 | prop("a")({ a: true }) as undefined;
5 | prop("a")({ b: 1 }) as number;
6 | prop("a")({ b: 1 }) as undefined;
7 | prop("a", true)({ b: 1 }) as number;
8 | prop("a", true)({ b: 1 }) as boolean;
9 | prop("a", "b")({ b: 1 }) as number;
10 | prop("a", "b")({ b: 1 }) as string;
11 |
12 | theme("a")({ theme: { a: 1 } }) as number;
13 | theme("a")({ theme: { a: 1 } }) as undefined;
14 | theme("a")({ theme: { a: true } }) as boolean;
15 | theme("a")({ theme: { a: true } }) as undefined;
16 | theme("a", "b")({ theme: { a: true } }) as boolean;
17 | theme("a", "b")({ theme: { a: true } }) as string;
18 | theme("a", "b")({ a: 1, theme: { a: true } }) as boolean;
19 | theme("a", "b")({ a: 1, theme: { a: true } }) as string;
20 |
21 | palette("a")({ theme: { palette: { a: "a" } } }) as string;
22 | palette("a")({ theme: { palette: { a: "a" } } }) as undefined;
23 | palette()({ theme: { palette: { a: "a", b: "b" } }, palette: "a" });
24 | palette(1)({ theme: { palette: { a: "a" } }, palette: "a" }) as string;
25 | palette(1)({ theme: { palette: { a: "a" } }, palette: "a" }) as undefined;
26 | palette("a", 1)({ theme: { palette: { a: "a" } } }) as string;
27 | palette("a", 1)({ theme: { palette: { a: "a" } } }) as undefined;
28 | palette("a", 1, "b")({ theme: { palette: { a: "a" } } }) as string;
29 | palette("a", 1, "b")({ theme: { palette: { a: "a" } } }) as undefined;
30 | palette("a", "b")({ theme: { palette: { a: "a" } } }) as string;
31 | palette("a", "b")({ theme: { palette: { a: "a" } } }) as undefined;
32 | palette(1, "b")({ theme: {} }) as string;
33 | palette(1, "b")({ theme: {} }) as undefined;
34 |
35 | ifProp("a", true)({ a: true }) as boolean;
36 | ifProp("a", true)({ a: true }) as undefined;
37 | ifProp("a", 1)({ a: true }) as number;
38 | ifProp("a", 1)({ a: true }) as undefined;
39 | ifProp("a", 1, 2)({ a: true }) as number;
40 | ifProp("a", "a")({ a: true }) as string;
41 | ifProp("a", "a")({ a: true }) as undefined;
42 | ifProp("a")({ a: true }) as undefined;
43 | ifProp("a", ifProp("b", "5", "0"), ifProp("c", "5", "0"))({ a: false, b: true, c: false }) as string;
44 |
45 | ifNotProp("a", true)({ a: true }) as boolean;
46 | ifNotProp("a", true)({ a: true }) as undefined;
47 | ifNotProp("a", 1)({ a: true }) as number;
48 | ifNotProp("a", 1)({ a: true }) as undefined;
49 | ifNotProp("a", 1, 2)({ a: true }) as number;
50 | ifNotProp("a", "a")({ a: true }) as string;
51 | ifNotProp("a", "a")({ a: true }) as undefined;
52 | ifNotProp("a")({ a: true }) as undefined;
53 | ifNotProp("a", ifNotProp("b", "5", "0"), ifNotProp("c", "5", "0"))({ a: false, b: true, c: false }) as string;
54 |
55 | switchProp("a", { a: true, b: 1 })({ a: "a" }) as boolean;
56 | switchProp("a", { a: true, b: 1 })({ a: "a" }) as number;
57 | switchProp("a", { a: true, b: 1 })({ a: "a" }) as undefined;
58 | switchProp("a", { a: true, b: 1 }, "a")({ a: "a" }) as boolean;
59 | switchProp("a", { a: true, b: 1 }, "a")({ a: "a" }) as number;
60 | switchProp("a", { a: true, b: 1 }, "a")({ a: "a" }) as string;
61 | switchProp("a", () => ({ a: "a" }))({ a: "a" }) as string;
62 |
63 | withProp("a", a => a)({ a: false }) as any;
64 | withProp("a", () => 1)({ a: false }) as number;
65 | withProp("a", () => "a")({ a: false }) as string;
66 | withProp("a", () => true)({ a: false }) as boolean;
67 | withProp("a", () => {})({ a: false }) as void;
68 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 |
6 | ## [1.7.2](https://github.com/diegohaz/styled-tools/compare/v1.7.1...v1.7.2) (2020-06-23)
7 |
8 |
9 | ### Bug Fixes
10 |
11 | * Update typings to handle nested ifProp ([#80](https://github.com/diegohaz/styled-tools/issues/80)) ([85a02ff](https://github.com/diegohaz/styled-tools/commit/85a02ff))
12 |
13 |
14 |
15 |
16 | ## [1.7.1](https://github.com/diegohaz/styled-tools/compare/v1.7.0...v1.7.1) (2019-01-22)
17 |
18 |
19 | ### Bug Fixes
20 |
21 | * Revert [#56](https://github.com/diegohaz/styled-tools/issues/56) ([#58](https://github.com/diegohaz/styled-tools/issues/58)) ([14ec733](https://github.com/diegohaz/styled-tools/commit/14ec733)), closes [#57](https://github.com/diegohaz/styled-tools/issues/57)
22 |
23 |
24 |
25 |
26 | # [1.7.0](https://github.com/diegohaz/styled-tools/compare/v1.6.0...v1.7.0) (2019-01-17)
27 |
28 |
29 | ### Features
30 |
31 | * Add support for deeply resolving properties ([#56](https://github.com/diegohaz/styled-tools/issues/56)) ([22daf6e](https://github.com/diegohaz/styled-tools/commit/22daf6e)), closes [#55](https://github.com/diegohaz/styled-tools/issues/55)
32 |
33 |
34 |
35 |
36 | # [1.6.0](https://github.com/diegohaz/styled-tools/compare/v1.5.2...v1.6.0) (2018-11-06)
37 |
38 |
39 | ### Features
40 |
41 | * **switchProp:** Add support for passing cases as a function ([#54](https://github.com/diegohaz/styled-tools/issues/54)) ([27437a2](https://github.com/diegohaz/styled-tools/commit/27437a2))
42 |
43 |
44 |
45 |
46 | ## [1.5.2](https://github.com/diegohaz/styled-tools/compare/v1.5.1...v1.5.2) (2018-10-15)
47 |
48 |
49 | ### Bug Fixes
50 |
51 | * **switchProp:** Fix boolean values ([4c09e1b](https://github.com/diegohaz/styled-tools/commit/4c09e1b))
52 |
53 |
54 |
55 |
56 | ## [1.5.1](https://github.com/diegohaz/styled-tools/compare/v1.5.0...v1.5.1) (2018-09-02)
57 |
58 |
59 | ### Bug Fixes
60 |
61 | * **ifProp:** Make it work properly when the test argument is an array ([e6f2608](https://github.com/diegohaz/styled-tools/commit/e6f2608))
62 |
63 |
64 |
65 |
66 | # [1.5.0](https://github.com/diegohaz/styled-tools/compare/v1.4.3...v1.5.0) (2018-09-02)
67 |
68 |
69 | ### Features
70 |
71 | * **palette:** Use `props.tone` if it wasn't passed in as argument ([ce36900](https://github.com/diegohaz/styled-tools/commit/ce36900))
72 |
73 |
74 |
75 |
76 | ## [1.4.3](https://github.com/diegohaz/styled-tools/compare/v1.4.2...v1.4.3) (2018-08-31)
77 |
78 |
79 | ### Bug Fixes
80 |
81 | * palette typings ([8d1e32d](https://github.com/diegohaz/styled-tools/commit/8d1e32d))
82 |
83 |
84 |
85 |
86 | ## [1.4.2](https://github.com/diegohaz/styled-tools/compare/v1.4.1...v1.4.2) (2018-08-30)
87 |
88 |
89 | ### Bug Fixes
90 |
91 | * theme typings ([68e22bd](https://github.com/diegohaz/styled-tools/commit/68e22bd))
92 |
93 |
94 |
95 |
96 | ## [1.4.1](https://github.com/diegohaz/styled-tools/compare/v1.4.0...v1.4.1) (2018-08-28)
97 |
98 |
99 | ### Bug Fixes
100 |
101 | * Make `palette` optional in `props.theme` ([da4f7d4](https://github.com/diegohaz/styled-tools/commit/da4f7d4))
102 |
103 |
104 |
105 |
106 | # [1.4.0](https://github.com/diegohaz/styled-tools/compare/v1.3.1...v1.4.0) (2018-08-28)
107 |
108 |
109 | ### Features
110 |
111 | * Add `palette` ([#50](https://github.com/diegohaz/styled-tools/issues/50)) ([c8e177d](https://github.com/diegohaz/styled-tools/commit/c8e177d))
112 |
113 |
114 |
115 |
116 | ## [1.3.1](https://github.com/diegohaz/styled-tools/compare/v1.3.0...v1.3.1) (2018-08-19)
117 |
118 |
119 | ### Bug Fixes
120 |
121 | * Make TypeScript typings more precise ([#48](https://github.com/diegohaz/styled-tools/issues/48)) ([3a46052](https://github.com/diegohaz/styled-tools/commit/3a46052))
122 |
123 |
124 |
125 |
126 | # [1.3.0](https://github.com/diegohaz/styled-tools/compare/v1.2.0...v1.3.0) (2018-08-18)
127 |
128 |
129 | ### Features
130 |
131 | * Add `theme` method ([#47](https://github.com/diegohaz/styled-tools/issues/47)) ([1514664](https://github.com/diegohaz/styled-tools/commit/1514664))
132 |
133 |
134 |
135 |
136 | # [1.2.0](https://github.com/diegohaz/styled-tools/compare/v1.1.0...v1.2.0) (2018-08-18)
137 |
138 |
139 | ### Features
140 |
141 | * Add TypeScript typings ([#46](https://github.com/diegohaz/styled-tools/issues/46)) ([4e1cc5a](https://github.com/diegohaz/styled-tools/commit/4e1cc5a)), closes [#40](https://github.com/diegohaz/styled-tools/issues/40)
142 |
143 |
144 |
145 |
146 | # [1.1.0](https://github.com/diegohaz/styled-tools/compare/v1.0.0...v1.1.0) (2018-08-08)
147 |
148 |
149 | ### Performance Improvements
150 |
151 | * Remove lodash dependency ([#45](https://github.com/diegohaz/styled-tools/issues/45)) ([bd06455](https://github.com/diegohaz/styled-tools/commit/bd06455))
152 |
153 |
154 |
155 |
156 | # [1.0.0](https://github.com/diegohaz/styled-tools/compare/v0.6.2...v1.0.0) (2018-07-23)
157 |
158 | Just bumping version.
159 |
160 |
161 |
162 |
163 | ## [0.6.2](https://github.com/diegohaz/styled-tools/compare/v0.6.1...v0.6.2) (2018-07-16)
164 |
165 |
166 | ### Features
167 |
168 | * **switchProp:** Add defaultCase parameter ([d4e5639](https://github.com/diegohaz/styled-tools/commit/d4e5639))
169 |
170 |
171 |
172 |
173 | ## [0.6.1](https://github.com/diegohaz/styled-tools/compare/v0.6.0...v0.6.1) (2018-07-15)
174 |
175 |
176 | ### Features
177 |
178 | * **ifProp:** Accept functions in values ([8e334b7](https://github.com/diegohaz/styled-tools/commit/8e334b7))
179 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # styled-tools 💅
2 |
3 | [](https://npmjs.org/package/styled-tools)
4 | [](https://npmjs.org/package/styled-tools)
5 | [](https://david-dm.org/diegohaz/styled-tools)
6 | [](https://travis-ci.org/diegohaz/styled-tools) [](https://codecov.io/gh/diegohaz/styled-tools/branch/master)
7 |
8 | Useful interpolated functions for [styled-components](https://github.com/styled-components/styled-components) 💅, [emotion](https://github.com/emotion-js/emotion) 👩🎤, [JSS](https://github.com/cssinjs/jss) and other CSS-in-JS libraries.
9 |
10 | ## Install
11 |
12 | npm:
13 |
14 | npm i styled-tools
15 |
16 | Yarn:
17 |
18 | yarn add styled-tools
19 |
20 | ## Usage
21 |
22 | ```jsx
23 | import styled, { css } from "styled-components";
24 | import { prop, ifProp, switchProp } from "styled-tools";
25 |
26 | const Button = styled.button`
27 | color: ${prop("color", "red")};
28 | font-size: ${ifProp({ size: "large" }, "20px", "14px")};
29 | background-color: ${switchProp("theme", {
30 | dark: "blue",
31 | darker: "mediumblue",
32 | darkest: "darkblue"
33 | })};
34 | `;
35 |
36 | // renders with color: blue
37 |
38 |
39 | // renders with color: red
40 |
41 |
42 | // renders with font-size: 20px
43 |
44 |
45 | // renders with background-color: mediumblue
46 |
47 | ```
48 |
49 | A more complex example:
50 |
51 | ```jsx
52 | const Button = styled.button`
53 | color: ${prop("theme.colors.white", "#fff")};
54 | font-size: ${ifProp({ size: "large" }, prop("theme.sizes.lg", "20px"), prop("theme.sizes.md", "14px"))};
55 | background-color: ${prop("theme.colors.black", "#000")};
56 |
57 | ${switchProp("kind", {
58 | dark: css`
59 | background-color: ${prop("theme.colors.blue", "blue")};
60 | border: 1px solid ${prop("theme.colors.blue", "blue")};
61 | `,
62 | darker: css`
63 | background-color: ${prop("theme.colors.mediumblue", "mediumblue")};
64 | border: 1px solid ${prop("theme.colors.mediumblue", "mediumblue")};
65 | `,
66 | darkest: css`
67 | background-color: ${prop("theme.colors.darkblue", "darkblue")};
68 | border: 1px solid ${prop("theme.colors.darkblue", "darkblue")};
69 | `
70 | })}
71 |
72 | ${ifProp("disabled", css`
73 | background-color: ${prop("theme.colors.gray", "#999")};
74 | border-color: ${prop("theme.colors.gray", "#999")};
75 | pointer-events: none;
76 | `)}
77 | `;
78 | ```
79 |
80 | ## API
81 |
82 |
83 |
84 | #### Table of Contents
85 |
86 | - [prop](#prop)
87 | - [Parameters](#parameters)
88 | - [Examples](#examples)
89 | - [theme](#theme)
90 | - [Parameters](#parameters-1)
91 | - [Examples](#examples-1)
92 | - [palette](#palette)
93 | - [Parameters](#parameters-2)
94 | - [Examples](#examples-2)
95 | - [ifProp](#ifprop)
96 | - [Parameters](#parameters-3)
97 | - [Examples](#examples-3)
98 | - [ifNotProp](#ifnotprop)
99 | - [Parameters](#parameters-4)
100 | - [Examples](#examples-4)
101 | - [withProp](#withprop)
102 | - [Parameters](#parameters-5)
103 | - [Examples](#examples-5)
104 | - [switchProp](#switchprop)
105 | - [Parameters](#parameters-6)
106 | - [Examples](#examples-6)
107 | - [Types](#types)
108 | - [Needle](#needle)
109 |
110 | ### prop
111 |
112 | Returns the value of `props[path]` or `defaultValue`
113 |
114 | #### Parameters
115 |
116 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
117 | - `defaultValue` **any**
118 |
119 | #### Examples
120 |
121 | ```javascript
122 | import styled from "styled-components";
123 | import { prop } from "styled-tools";
124 |
125 | const Button = styled.button`
126 | color: ${prop("color", "red")};
127 | `;
128 | ```
129 |
130 | Returns **PropsFn**
131 |
132 | ### theme
133 |
134 | Same as `prop`, except that it returns `props.theme[path]` instead of
135 | `props[path]`.
136 |
137 | #### Parameters
138 |
139 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
140 | - `defaultValue` **any**
141 |
142 | #### Examples
143 |
144 | ```javascript
145 | import styled from "styled-components";
146 | import { theme } from "styled-tools";
147 |
148 | const Button = styled.button`
149 | color: ${theme("button.color", "red")};
150 | `;
151 | ```
152 |
153 | ### palette
154 |
155 | Returns `props.theme.palette[key || props.palette][tone || props.tone || 0]` or `defaultValue`.
156 |
157 | #### Parameters
158 |
159 | - `keyOrTone` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))**
160 | - `toneOrDefaultValue` **any**
161 | - `defaultValue` **any**
162 |
163 | #### Examples
164 |
165 | ```javascript
166 | import styled, { ThemeProvider } from "styled-components";
167 | import { palette } from "styled-tools";
168 |
169 | const theme = {
170 | palette: {
171 | primary: ['#1976d2', '#2196f3', '#71bcf7', '#c2e2fb'],
172 | secondary: ['#c2185b', '#e91e63', '#f06292', '#f8bbd0']
173 | }
174 | };
175 |
176 | const Button = styled.button`
177 | color: ${palette(1)}; // props.theme.palette[props.palette][1]
178 | color: ${palette("primary", 1)}; // props.theme.palette.primary[1]
179 | color: ${palette("primary")}; // props.theme.palette.primary[props.tone || 0]
180 | color: ${palette("primary", -1)}; // props.theme.palette.primary[3]
181 | color: ${palette("primary", 10)}; // props.theme.palette.primary[3]
182 | color: ${palette("primary", -10)}; // props.theme.palette.primary[0]
183 | color: ${palette("primary", 0, "red")}; // props.theme.palette.primary[0] || red
184 | `;
185 |
186 |