-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
296 additions
and
123 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
78 changes: 78 additions & 0 deletions
78
src/h5web/toolbar/controls/DomainSlider/BoundEditor.module.css
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,78 @@ | ||
.boundEditor { | ||
display: flex; | ||
align-items: center; | ||
margin-bottom: 0.75rem; | ||
font-weight: bold; | ||
} | ||
|
||
.label { | ||
width: 2.5em; | ||
margin: 0 1rem 0 0; | ||
text-transform: uppercase; | ||
font-size: inherit; | ||
color: var(--near-black); | ||
} | ||
|
||
.value { | ||
flex: 1 1 0%; | ||
width: 0; /* ensures this input shrinks before filling the available space */ | ||
height: 1.875rem; /* maintain height regardless of font size */ | ||
margin-right: 0.375rem; | ||
padding: 0.25rem 0.375rem; | ||
background-color: rgba(255, 255, 255, 0.5); | ||
border: 1px solid transparent; | ||
border-radius: 0.125rem; | ||
box-shadow: 0 0 2px var(--dark-slate-gray); | ||
text-align: right; | ||
color: var(--near-black); | ||
font-weight: inherit; | ||
line-height: inherit; | ||
transition: background-color 0.05s ease-in-out, box-shadow 0.05s ease-in-out; | ||
cursor: text; | ||
} | ||
|
||
.value:hover { | ||
box-shadow: 1px 1px 2px 1px var(--dark-gray); | ||
} | ||
|
||
.value:focus { | ||
box-shadow: 1px 1px 2px 1px var(--secondary-dark); | ||
outline: none; | ||
} | ||
|
||
.boundEditor[data-error] .label, | ||
.boundEditor[data-error] .value { | ||
color: var(--warn); | ||
} | ||
|
||
.boundEditor[data-editing='true'] .value { | ||
background-color: var(--white); | ||
border-color: var(--secondary-dark); | ||
outline: none; | ||
font-weight: 600; | ||
font-size: 0.9375em; | ||
line-height: calc(1.2 / 0.9375); | ||
} | ||
|
||
.boundEditor[data-editing='true'] .value:hover { | ||
box-shadow: 1px 1px 2px 1px var(--secondary-dark); | ||
} | ||
|
||
.action { | ||
composes: btn-clean from global; | ||
display: flex; | ||
align-items: center; | ||
padding: 0.25rem; | ||
font-size: 1.125em; | ||
border-radius: 0.5rem; | ||
transition: background-color 0.05s ease-in-out, box-shadow 0.05s ease-in-out; | ||
} | ||
|
||
.action:hover { | ||
background-color: var(--secondary-light); | ||
box-shadow: var(--btn-shadow-idle) var(--btn-shadow-color); | ||
} | ||
|
||
.action:active { | ||
box-shadow: var(--btn-shadow-pressed) var(--btn-shadow-color); | ||
} |
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,85 @@ | ||
import { ReactElement, useEffect, useRef, useState } from 'react'; | ||
import { FiCheck, FiSlash } from 'react-icons/fi'; | ||
import { formatValue } from '../../../utils'; | ||
import styles from './BoundEditor.module.css'; | ||
|
||
interface Props { | ||
label: string; | ||
value: number; | ||
isEditing: boolean; | ||
hasError: boolean; | ||
onEditToggle: (force: boolean) => void; | ||
onChange: (val: number) => void; | ||
} | ||
|
||
function BoundEditor(props: Props): ReactElement { | ||
const { label, value, isEditing, hasError, onEditToggle, onChange } = props; | ||
|
||
const id = `${label}-bound`; | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const [inputValue, setInputValue] = useState(formatValue(value)); | ||
|
||
useEffect(() => { | ||
setInputValue(isEditing ? value.toString() : formatValue(value)); | ||
}, [isEditing, value, setInputValue]); | ||
|
||
useEffect(() => { | ||
if (!isEditing) { | ||
// Remove focus from min field when editing is turned off | ||
inputRef.current?.blur(); | ||
} | ||
|
||
if (isEditing && label === 'Min') { | ||
// Give focus to min field when opening tooltip in edit mode | ||
inputRef.current?.focus(); | ||
} | ||
}, [isEditing, label]); | ||
|
||
return ( | ||
<form | ||
className={styles.boundEditor} | ||
data-error={hasError || undefined} | ||
data-editing={isEditing} | ||
onSubmit={(evt) => { | ||
evt.preventDefault(); | ||
onChange(Number.parseFloat(inputValue)); | ||
onEditToggle(false); | ||
}} | ||
> | ||
<label id={`${id}-label`} className={styles.label} htmlFor={id}> | ||
<abbr title={value.toString()}>{label}</abbr> | ||
</label> | ||
|
||
<input | ||
id={id} | ||
ref={inputRef} | ||
className={styles.value} | ||
type="text" | ||
name="bound" | ||
value={inputValue} | ||
aria-labelledby={`${id}-label`} // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/566 | ||
onChange={(evt) => setInputValue(evt.target.value)} | ||
onFocus={() => { | ||
if (!isEditing) { | ||
onEditToggle(true); | ||
} | ||
}} | ||
/> | ||
|
||
<button className={styles.action} type="submit" disabled={!isEditing}> | ||
<FiCheck>Apply</FiCheck> | ||
</button> | ||
<button | ||
className={styles.action} | ||
type="button" | ||
disabled={!isEditing} | ||
onClick={() => onEditToggle(false)} | ||
> | ||
<FiSlash>Cancel</FiSlash> | ||
</button> | ||
</form> | ||
); | ||
} | ||
|
||
export default BoundEditor; |
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
Oops, something went wrong.