-
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #492 from acelaya-forks/feature/qr-code-color
Support color and background color in QR codes modal
- Loading branch information
Showing
20 changed files
with
352 additions
and
149 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
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,7 @@ | ||
@import '../../../node_modules/@shlinkio/shlink-frontend-kit/dist/base'; | ||
|
||
.qr-code-modal__controls { | ||
@media (min-width: $lgMin) { | ||
width: 16rem; | ||
} | ||
} |
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,30 @@ | ||
import { faArrowRotateLeft } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import type { FC } from 'react'; | ||
import { ColorInput } from '../../../utils/components/ColorInput'; | ||
import { SubtleButton } from '../../../utils/components/SubtleButton'; | ||
|
||
export type QrColorControlProps = { | ||
name: string; | ||
color?: string; | ||
/** Initial color to set when transitioning from default to custom */ | ||
initialColor: string; | ||
onChange: (newColor?: string) => void; | ||
}; | ||
|
||
export const QrColorControl: FC<QrColorControlProps> = ({ name, color, initialColor, onChange }) => ( | ||
<> | ||
{color === undefined ? ( | ||
<SubtleButton className="text-start fst-italic w-100" onClick={() => onChange(initialColor)}> | ||
<span className="indivisible">Customize {name}</span> | ||
</SubtleButton> | ||
) : ( | ||
<div className="d-flex gap-1 w-100"> | ||
<ColorInput color={color} onChange={onChange} name={name} /> | ||
<SubtleButton label={`Default ${name}`} onClick={() => onChange(undefined)}> | ||
<FontAwesomeIcon icon={faArrowRotateLeft} /> | ||
</SubtleButton> | ||
</div> | ||
)} | ||
</> | ||
); |
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
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,22 @@ | ||
import { useElementRef } from '@shlinkio/shlink-frontend-kit'; | ||
import type { FC } from 'react'; | ||
import { Input, InputGroup } from 'reactstrap'; | ||
import type { ColorPickerProps } from './ColorPicker'; | ||
import { ColorPicker } from './ColorPicker'; | ||
|
||
export const ColorInput: FC<Omit<ColorPickerProps, 'className'>> = ({ color, onChange, name }) => { | ||
const colorPickerRef = useElementRef<HTMLInputElement>(); | ||
|
||
return ( | ||
<InputGroup> | ||
<ColorPicker name={name} color={color} onChange={onChange} className="input-group-text" ref={colorPickerRef} /> | ||
<Input | ||
readOnly | ||
value={color} | ||
onClick={() => colorPickerRef.current?.click()} | ||
aria-label={name} | ||
data-testid="text-input" | ||
/> | ||
</InputGroup> | ||
); | ||
}; |
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,38 @@ | ||
import { faPalette as colorIcon } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { clsx } from 'clsx'; | ||
import { forwardRef } from 'react'; | ||
import { Input } from 'reactstrap'; | ||
import { isLightColor } from '../helpers/color'; | ||
|
||
export type ColorPickerProps = { | ||
name: string; | ||
color: string; | ||
onChange: (newColor: string) => void; | ||
className?: string; | ||
}; | ||
|
||
export const ColorPicker = forwardRef<HTMLInputElement, ColorPickerProps>( | ||
({ name, color, onChange, className }, ref) => ( | ||
<div | ||
className={clsx('p-0 position-relative', className)} | ||
style={{ backgroundColor: color, borderColor: color }} | ||
> | ||
<FontAwesomeIcon | ||
icon={colorIcon} | ||
className="position-absolute top-50 start-50 translate-middle" | ||
// Text color should be dynamically calculated to keep contrast | ||
style={{ color: isLightColor(color.substring(1)) ? '#000' : 'fff' }} | ||
/> | ||
<Input | ||
className="form-control-color opacity-0" | ||
type="color" | ||
value={color} | ||
onChange={(e) => onChange(e.target.value)} | ||
innerRef={ref} | ||
name={name} | ||
aria-label={name} | ||
/> | ||
</div> | ||
), | ||
); |
Oops, something went wrong.