-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from covidpass-org/color-selector
Color selector
- Loading branch information
Showing
9 changed files
with
131 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, {useState} from 'react' | ||
import {RadioGroup} from '@headlessui/react' | ||
import {COLORS, rgbToHex} from "../src/colors"; | ||
|
||
interface ColorsProps { | ||
initialValue: COLORS, | ||
onChange(value: COLORS): void; | ||
} | ||
|
||
function Colors(props: ColorsProps): JSX.Element { | ||
let [color, setColor] = useState(props.initialValue) | ||
|
||
return ( | ||
<RadioGroup<"div", COLORS> | ||
className="flex flex-wrap" value={color} | ||
onChange={function (value) { | ||
setColor(value); | ||
props.onChange(value); | ||
} | ||
}> | ||
{Object.values(COLORS).map((color) => { | ||
return ( | ||
<RadioGroup.Option value={color} key={color} className="outline-none"> | ||
{({checked}) => ( | ||
<div | ||
key={color} | ||
className={`${color !== COLORS.WHITE ? 'ring-white' : 'ring-black'} ring-2 shadow-xl cursor-pointer rounded-md w-10 h-10 flex items-center justify-center m-2`} | ||
style={{backgroundColor: rgbToHex(color), WebkitAppearance: 'none'}} | ||
> | ||
{checked && | ||
<svg className={`${color !== COLORS.WHITE ? 'text-white' : 'text-black'} h-6 w-6`} fill="none" | ||
viewBox="0 0 24 24" stroke="currentColor"> | ||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2.5" d="M5 13l4 4L19 7"/> | ||
</svg> | ||
} | ||
</div> | ||
)} | ||
</RadioGroup.Option> | ||
) | ||
})} | ||
</RadioGroup> | ||
) | ||
} | ||
|
||
export default Colors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Accessible colors from https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color | ||
|
||
export enum COLORS { | ||
WHITE = 'rgb(255, 255, 255)', | ||
BLACK = 'rgb(0, 0, 0)', | ||
GREY = 'rgb(36, 36, 38)', | ||
BLUE = 'rgb(0, 64, 221)', | ||
BROWN = 'rgb(127, 101, 69)', | ||
CYAN = 'rgb(0, 113, 164)', | ||
GREEN = 'rgb(36, 138, 61)', | ||
INDIGO = 'rgb(54, 52, 163)', | ||
MINT = 'rgb(12, 129, 123)', | ||
ORANGE = 'rgb(201, 52, 0)', | ||
PINK = 'rgb(211, 15, 69)', | ||
PURPLE = 'rgb(137, 68, 171)', | ||
RED = 'rgb(215, 0, 21)', | ||
TEAL = 'rgb(0, 130, 153)', | ||
YELLOW = 'rgb(178, 80, 0)' | ||
} | ||
|
||
export function rgbToHex(rgbString: string) { | ||
let a = rgbString.split("(")[1].split(")")[0]; | ||
let values = a.split(","); | ||
|
||
let b = values.map(function (value) { | ||
let x = parseInt(value).toString(16); | ||
return (x.length == 1) ? "0" + x : x; | ||
}) | ||
|
||
return "#" + b.join(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
module.exports = { | ||
mode: 'jit', | ||
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'], | ||
darkMode: 'media', | ||
theme: { | ||
extend: {}, | ||
}, | ||
variants: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
mode: 'jit', | ||
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'], | ||
darkMode: 'media', | ||
theme: { | ||
extend: {}, | ||
}, | ||
variants: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
} |
Oops, something went wrong.