This repository has been archived by the owner on May 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to customize Player LEDs (PWM and RGB) (#66)
* Fix jumpy page when open/closing picker * Allow saving colors * Allow gradient selection * Fix bug when saving color without selection * Save gradient color selections * Fix ALL button resetting gradient values * Update led theme label on backup page * Create ColorPicker component * Get PLED config working * Fix build * Fix label * Fix custom validators and usedPins in AppContext * Centralize usedPins array in frontend AppContext * Finish up PLED interface * Fix usedPins on dev server * Logging for fallback requests on dev server * Fix bug with post data for LED config * Fix possible double submit on LED config page * Fix blinky popover * Add dynamic suggested start index for RGB PLEDs * Remove intro text for PLED section
- Loading branch information
Showing
17 changed files
with
725 additions
and
132 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import Button from 'react-bootstrap/Button'; | ||
import Col from 'react-bootstrap/Col'; | ||
import Container from 'react-bootstrap/Container'; | ||
import Form from 'react-bootstrap/Form'; | ||
import Overlay from 'react-bootstrap/Overlay'; | ||
import Popover from 'react-bootstrap/Popover'; | ||
import Row from 'react-bootstrap/Row'; | ||
import { SketchPicker } from '@hello-pangea/color-picker'; | ||
|
||
import { AppContext } from '../Contexts/AppContext'; | ||
import LEDColors from '../Data/LEDColors'; | ||
|
||
import './ColorPicker.scss'; | ||
|
||
const ledColors = LEDColors.map(c => ({ title: c.name, color: c.value})); | ||
const customColors = (colors) => colors.map(c => ({ title: c, color: c })); | ||
|
||
const ColorPicker = ({ types, onChange, onDismiss, pickerOnly, placement, show, target, title, ...props }) => { | ||
const { savedColors, setSavedColors } = useContext(AppContext); | ||
const [colorPalette, setColorPalette] = useState([...ledColors, ...customColors(savedColors)]); | ||
const [colorTypes, setColorTypes] = useState(types); | ||
const [selectedColor, setSelectedColor] = useState('#000000'); | ||
const [selectedColorType, setSelectedColorType] = useState(types[0]); | ||
|
||
const deleteCurrentColor = () => { | ||
const colorIndex = savedColors.indexOf(selectedColor); | ||
if (colorIndex < 0) | ||
return; | ||
|
||
const newColors = [...savedColors]; | ||
newColors.splice(colorIndex, 1); | ||
setSavedColors(newColors); | ||
setColorPalette([...ledColors, ...customColors(newColors)]); | ||
}; | ||
|
||
const saveCurrentColor = () => { | ||
if (!selectedColor || colorPalette.filter(c => c.color === selectedColor).length > 0) | ||
return; | ||
|
||
const newColors = [...savedColors]; | ||
newColors.push(selectedColor); | ||
setSavedColors(newColors); | ||
setColorPalette([...ledColors, ...customColors(newColors)]); | ||
}; | ||
|
||
const selectColor = (c, e) => { | ||
if (onChange) | ||
onChange(c.hex, e); | ||
|
||
selectedColorType.value = c.hex; | ||
|
||
setSelectedColor(c.hex); | ||
setColorTypes(colorTypes); | ||
}; | ||
|
||
useEffect(() => { | ||
// Hide color picker when anywhere but picker is clicked | ||
window.addEventListener('click', (e) => onDismiss(e)); | ||
setSelectedColorType(colorTypes[0]); | ||
setSelectedColor(colorTypes[0].value); | ||
}, []); | ||
|
||
return ( | ||
<Overlay | ||
show={show} | ||
target={target} | ||
placement={placement || 'bottom'} | ||
container={this} | ||
containerPadding={20} | ||
> | ||
<Popover onClick={(e) => e.stopPropagation()}> | ||
<Container className="color-picker"> | ||
<h6 className="text-center">{title}</h6> | ||
<Row> | ||
{colorTypes.map(((o, i) => | ||
<Form.Group as={Col} | ||
key={`colorType${i}`} | ||
className={`${o === selectedColorType ? 'selected' : ''}`} | ||
onClick={() => setSelectedColorType(o)} | ||
> | ||
{o.title && <Form.Label>{o.title}</Form.Label>} | ||
<div | ||
className={`color color-normal`} | ||
style={{ backgroundColor: o.value }} | ||
> | ||
</div> | ||
</Form.Group> | ||
))} | ||
</Row> | ||
<Row> | ||
<Col> | ||
<SketchPicker | ||
color={selectedColorType.value} | ||
onChange={(c, e) => selectColor(c, e)} | ||
disableAlpha={true} | ||
presetColors={colorPalette} | ||
width={180} | ||
/> | ||
</Col> | ||
</Row> | ||
<div className="button-group d-flex justify-content-between mt-2"> | ||
<Button size="sm" onClick={() => saveCurrentColor()}>Save Color</Button> | ||
<Button size="sm" onClick={() => deleteCurrentColor()}>Delete Color</Button> | ||
</div> | ||
</Container> | ||
</Popover> | ||
</Overlay> | ||
) | ||
}; | ||
|
||
export default ColorPicker; |
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,39 @@ | ||
.color-picker { | ||
user-select: none; | ||
padding-bottom: 10px; | ||
|
||
h6 { | ||
margin-top: 8px; | ||
} | ||
|
||
.color-option { | ||
justify-content: flex-start; | ||
cursor: pointer; | ||
font-size: 0.8rem; | ||
|
||
label { | ||
cursor: pointer; | ||
margin: 0 auto 4px; | ||
text-align: center; | ||
width: 100%; | ||
font-size: 0.85rem; | ||
} | ||
|
||
&.selected { | ||
background-color: #DEDEDE; | ||
} | ||
} | ||
|
||
.color { | ||
display: flex; | ||
|
||
height: 40px !important; | ||
width: 40px !important; | ||
margin: 0 auto 10px; | ||
border: 1px solid black; | ||
} | ||
|
||
.sketch-picker { | ||
margin-top: 10px; | ||
} | ||
} |
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
Oops, something went wrong.