Skip to content

Commit

Permalink
feat(SalariesInput): add hasValue state with custom styling
Browse files Browse the repository at this point in the history
To clarify that a file has already been uploaded, and a new upload will override these values
  • Loading branch information
mathiazom committed Sep 9, 2024
1 parent 339e548 commit 13375b2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
5 changes: 5 additions & 0 deletions studio/components/salariesInput/SalariesInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import {
import { SalariesParseErrorsToastDescription } from "./components/SalariesParseErrorsToastDescription";
import SalariesFileUpload from "./components/SalariesFileUpload";
import SalariesTableEditor from "./components/SalariesTableEditor";
import { useState } from "react";

export const SalariesInput = (props: StringInputProps) => {
const toast = useToast();

const [hasValue, setHasValue] = useState(props.value !== undefined);

const salaries =
props.value === undefined
? undefined
Expand All @@ -31,6 +34,7 @@ export const SalariesInput = (props: StringInputProps) => {

function handleSalariesChangedFromFile(salariesFromFile: Salaries) {
props.onChange(set(salariesAsStoredString(salariesFromFile)));
setHasValue(true);
}

function handleSalariesFileParseErrors(errors: SalariesParseError[]) {
Expand All @@ -46,6 +50,7 @@ export const SalariesInput = (props: StringInputProps) => {
<Stack space={4}>
<Inline space={2}>
<SalariesFileUpload
hasValue={hasValue}
onSalariesChanged={handleSalariesChangedFromFile}
onParseErrors={handleSalariesFileParseErrors}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { ChangeEvent, useState, MouseEvent } from "react";
const UPLOAD_CSV_INPUT_ID = "upload-csv-input";

interface SalariesFileUploadProps {
hasValue?: boolean;
onSalariesChanged: (salaries: Salaries) => void;
onParseErrors: (errors: SalariesParseError[]) => void;
}

const SalariesFileUpload = ({
hasValue,
onSalariesChanged,
onParseErrors,
}: SalariesFileUploadProps) => {
Expand Down Expand Up @@ -78,10 +80,12 @@ const SalariesFileUpload = ({
<Box className={styles.uploadButtonWrapper}>
<label
htmlFor={UPLOAD_CSV_INPUT_ID}
className={styles.uploadButtonContent}
className={`${styles.uploadButtonContent}${hasValue ? ` ${styles.reUpload}` : ""}`}
>
<UploadIcon className={styles.uploadButtonIcon} />
<span className={styles.uploadButtonText}>Upload (.csv)</span>
<span className={styles.uploadButtonText}>
{hasValue ? "Re-upload" : "Upload"} (.csv)
</span>
</label>
</Box>
{filename && (
Expand Down
24 changes: 14 additions & 10 deletions studio/components/salariesInput/salariesInput.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,28 @@
padding: 0.45rem 0.6rem 0.45rem 0.5rem !important;
background-color: #252837; /* TODO: find Sanity Studio color variable */
border-radius: 0.1875rem;
color: white;

&:hover {
background-color: #1b1d27; /* TODO: find Sanity Studio color variable */
}

&.hasValue {
background-color: rgb(246, 246, 248);
color: black;
border: 1px solid rgb(230, 230, 234);
}
}

[data-scheme="dark"] .uploadButtonContent {
background-color: lightgray;
color: black;

&.hasValue {
background-color: rgb(25, 26, 36);
color: rgb(228, 229, 233);
border: 1px solid rgb(228, 229, 233);
}
}

.uploadButton {
Expand All @@ -42,20 +56,10 @@

.uploadButtonIcon {
font-size: 1.35rem;
color: white;
}

[data-scheme="dark"] .uploadButtonIcon {
color: black;
}

.uploadButtonText {
font-size: 0.8125rem;
color: white;
}

[data-scheme="dark"] .uploadButtonText {
color: black;
}

.tableHeader {
Expand Down

0 comments on commit 13375b2

Please sign in to comment.