Skip to content

Commit

Permalink
Start empty error signal (but still some work to do, like sizing on n…
Browse files Browse the repository at this point in the history
…umbers and maybe moving the icon)
  • Loading branch information
thsparks committed Mar 9, 2024
1 parent 8385f71 commit c6e5597
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion teachertool/src/components/ActiveRubricDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ActiveRubricDisplay: React.FC<ActiveRubricDisplayProps> = ({}) => {
<DebouncedInput
label={Strings.Name}
ariaLabel={Strings.Name}
onChange={setRubricName}
onDebouncedChange={setRubricName}
placeholder={Strings.RubricName}
initialValue={teacherTool.rubric.name}
preserveValueOnBlur={true}
Expand Down
15 changes: 13 additions & 2 deletions teachertool/src/components/CriteriaInstanceDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { classList } from "react-common/components/util";
import { splitCriteriaTemplate } from "../utils";
// eslint-disable-next-line import/no-internal-modules
import css from "./styling/CriteriaInstanceDisplay.module.scss";
import { useState } from "react";

interface InlineInputSegmentProps {
initialValue: string;
Expand All @@ -22,18 +23,29 @@ const InlineInputSegment: React.FC<InlineInputSegmentProps> = ({
shouldExpand,
numeric,
}) => {
function onChange(newValue: string) {
const [isEmpty, setIsEmpty] = useState(!initialValue);

function onDebouncedChange(newValue: string) {
setParameterValue(instance.instanceId, param.name, newValue);
}

function onChange(newValue: string) {
// Keep this out of the debounced version to avoid delayed appearance.
setIsEmpty(!newValue);
}

return (
<DebouncedInput
className={classList(
css["inline-input"],
numeric ? css["number-input"] : css["string-input"],
shouldExpand ? css["long"] : undefined,
isEmpty ? css["error"] : undefined
)}
icon={isEmpty ? "fas fa-exclamation-triangle" : undefined}
iconTitle={isEmpty ? lf("Missing value") : undefined}
initialValue={initialValue}
onDebouncedChange={onDebouncedChange}
onChange={onChange}
preserveValueOnBlur={true}
placeholder={numeric ? "0" : param.name}
Expand All @@ -47,7 +59,6 @@ const InlineInputSegment: React.FC<InlineInputSegmentProps> = ({
interface CriteriaInstanceDisplayProps {
criteriaInstance: CriteriaInstance;
}

export const CriteriaInstanceDisplay: React.FC<CriteriaInstanceDisplayProps> = ({ criteriaInstance }) => {
const catalogCriteria = getCatalogCriteriaWithId(criteriaInstance.catalogCriteriaId);
if (!catalogCriteria) {
Expand Down
10 changes: 7 additions & 3 deletions teachertool/src/components/DebouncedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import { Input, InputProps } from "react-common/components/controls/Input";

export interface DebouncedInputProps extends InputProps {
intervalMs?: number; // Default 500 ms
onDebouncedChange: (newValue: string) => void;
}

// This functions like the React Common Input, but debounces onChange calls,
// so if onChange is called multiple times in quick succession, it will only
// be executed once after a pause of the specified `interval` in milliseconds.
export const DebouncedInput: React.FC<DebouncedInputProps> = ({ intervalMs = 500, ...props }) => {
export const DebouncedInput: React.FC<DebouncedInputProps> = ({ onDebouncedChange, intervalMs = 500, ...props }) => {
const timerId = useRef<NodeJS.Timeout | undefined>(undefined);
const latestValue = useRef<string>("");

const sendChange = () => {
if (props.onChange) {
props.onChange(latestValue.current);
if (onDebouncedChange) {
onDebouncedChange(latestValue.current);
}
};

Expand All @@ -37,6 +38,9 @@ export const DebouncedInput: React.FC<DebouncedInputProps> = ({ intervalMs = 500
}

timerId.current = setTimeout(sendChange, intervalMs);
if (props.onChange) {
props.onChange(newValue);
}
};

return <Input {...props} onChange={onChangeDebounce} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@
text-align: center;
padding: 0;
}

&.error {
div[class*="common-input-group"] {
border: solid 1px var(--pxt-error-accent);
background-color: var(--pxt-error-background);

input::placeholder {
color: var(--pxt-page-foreground);
}
}
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions teachertool/src/components/styling/ShareLinkInput.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@
input::placeholder {
text-align: center;
}

i {
background-color: var(--pxt-content-background);
border-radius: 99px;
width: 1.5rem;
height: 1.5rem;
top: 0;
bottom: 0;
right: 0.25rem;
margin-top: auto;
margin-bottom: auto;

&::before {
font-size: 1rem;
line-height: 1.5rem;
color: var(--pxt-content-foreground);
filter: saturate(0%);
}
}
}
}

Expand Down
19 changes: 0 additions & 19 deletions teachertool/src/style.overrides/Input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,5 @@
font-style: italic;
}
}

i {
background-color: var(--pxt-content-background);
border-radius: 99px;
width: 1.5rem;
height: 1.5rem;
top: 0;
bottom: 0;
right: 0.25rem;
margin-top: auto;
margin-bottom: auto;

&::before {
font-size: 1rem;
line-height: 1.5rem;
color: var(--pxt-content-foreground);
filter: saturate(0%);
}
}
}
}

0 comments on commit c6e5597

Please sign in to comment.