Files
Tom Moor bcf282a2f6 feat: Auto-save settings and tidy settings layout (#14569)
* feat: Auto-save General and Profile settings, add settings sections

- Save General and Profile fields on change and remove the Save button
- Add SettingsSection with consistent spacing and a tinted Danger block
- Right-align setting controls and center switches in their row
- Let descriptions use the full row width beside switches

* fix: Avoid settings autosave overwrites and IME Enter saves

- Send only the changed team preference so concurrent saves do not revert each other
- Save separate editing as a single preference instead of the whole team
- Treat a cleared color input as empty so the default is restored
- Ignore Enter during IME composition

* feat: Add change and remove icon buttons below image inputs

- Replace the Remove button with edit and trash icon buttons with tooltips
- Show an upload icon on the image hover overlay
- Re-render ImageInput when the image changes so the remove action appears immediately

* feat: Use footer buttons in the change profile picture dialog

- Add Replace and Delete buttons beside Done in the admin avatar dialog
- Add showActions and an open handle to ImageInput so dialogs can supply their own controls

* fix: Style the danger section with an outer shadow instead of tinted text
2026-11-13 04:01:55 +00:00

136 lines
2.6 KiB
TypeScript

import { transparentize } from "polished";
import * as React from "react";
import styled from "styled-components";
import { breakpoint } from "@shared/styles/breakpoint";
import Flex from "~/components/Flex";
import Text from "~/components/Text";
type Props = {
children?: React.ReactNode;
label: React.ReactNode;
description?: React.ReactNode;
name: string;
visible?: boolean;
border?: boolean;
compact?: boolean;
};
const Row = styled(Flex)<{ $border?: boolean; $compact?: boolean }>`
padding: ${(props) => (props.$compact ? "12px 0" : "22px 0")};
align-items: ${(props) => (props.$compact ? "center" : "initial")};
border-bottom: 1px solid
${(props) =>
props.$border === false
? "transparent"
: transparentize(0.5, props.theme.divider)};
&:last-child {
border-bottom: 0;
}
/* Center switches, unless the text column also holds a field. */
&:has(> :last-child > [role="switch"]):not(
:has(> :first-child :is(input, textarea))
) {
align-items: center;
}
/* A switch column is only as wide as the switch. */
&:has(> :last-child > [role="switch"]) > :last-child {
flex: 0 0 auto;
}
${breakpoint("mobile", "tablet")`
&:has([role="switch"]) {
gap: 16px;
> :first-child {
min-width: 0;
}
> :last-child {
flex: 0 0 auto;
}
}
&:not(:has([role="switch"])) {
flex-direction: column;
gap: 12px;
> :last-child > * {
align-self: stretch;
}
}
`};
`;
const Column = styled.div`
display: flex;
flex-direction: column;
flex-basis: 100%;
flex: 1;
&:first-child {
min-width: 50%;
${breakpoint("tablet")`
min-width: 65%;
`}
}
&:last-child {
min-width: 0;
> * {
align-self: flex-end;
}
/* Text fields and selects fill the column. */
> :has(input:not([type="file"]), textarea, [role="combobox"]) {
align-self: stretch;
}
}
${breakpoint("tablet")`
p {
margin-bottom: 0;
}
`};
`;
const Label = styled(Text)`
margin-bottom: 4px;
`;
const SettingRow: React.FC<Props> = ({
visible,
description,
compact,
name,
label,
border,
children,
}: Props) => {
if (visible === false) {
return null;
}
return (
<Row gap={32} $border={border} $compact={compact}>
<Column>
<Label as="h3">
<label htmlFor={name}>{label}</label>
</Label>
{description && (
<Text as="p" type="secondary">
{description}
</Text>
)}
</Column>
<Column>{children}</Column>
</Row>
);
};
export default SettingRow;