MCPcopy Create free account
hub / github.com/callstack/react-native-paper / CustomColors

Function CustomColors

docs/src/components/DynamicColorTheme.tsx:186–244  ·  view source on GitHub ↗
({
  customColors,
  setCustomColors,
}: {
  customColors: CustomColorEntry[];
  setCustomColors: React.Dispatch<React.SetStateAction<CustomColorEntry[]>>;
})

Source from the content-addressed store, hash-verified

184let uniqColorKey = 0;
185
186const CustomColors = ({
187 customColors,
188 setCustomColors,
189}: {
190 customColors: CustomColorEntry[];
191 setCustomColors: React.Dispatch<React.SetStateAction<CustomColorEntry[]>>;
192}) => {
193 const addCustomColor = () => {
194 const newColor = {
195 key: `custom${++uniqColorKey}`,
196 name: `custom${customColors.length}`,
197 hex: defaultColor,
198 };
199 setCustomColors((colors) => [...colors, newColor]);
200 };
201
202 const setCustomColor = (key: string, hex: string) => {
203 setCustomColors((colors) =>
204 colors.map((color) => (color.key === key ? { ...color, hex } : color))
205 );
206 };
207
208 const setCustomName = (key: string, name: string) => {
209 setCustomColors((colors) =>
210 colors.map((color) => (color.key === key ? { ...color, name } : color))
211 );
212 };
213
214 const deleteCustomColor = (key: string) =>
215 setCustomColors((colors) => colors.filter((color) => key !== color.key));
216
217 return (
218 <>
219 {customColors.map(({ key, name, hex }, index) => (
220 <CustomColor
221 key={key}
222 uniqKey={key}
223 name={name}
224 index={index}
225 color={hex}
226 setCustomColor={setCustomColor}
227 deleteCustomColor={deleteCustomColor}
228 setCustomName={setCustomName}
229 />
230 ))}
231
232 <tr>
233 <td colSpan={2} align="center">
234 <button
235 onClick={addCustomColor}
236 className="color-picker-action-button"
237 >
238 + Add custom color
239 </button>
240 </td>
241 </tr>
242 </>
243 );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…