feat: Add cursor style user preference (#4199)

* feat: Add cursor style user preference

* Remove headings for now
This commit is contained in:
Tom Moor
2022-10-01 13:39:45 +02:00
committed by GitHub
parent ee8c47eb3b
commit b9bf2e58cb
37 changed files with 68 additions and 38 deletions

View File

@@ -67,6 +67,7 @@ const Item = styled(Link)<{ $highlight: boolean; $withIcon: boolean }>`
display: flex; display: flex;
flex-shrink: 1; flex-shrink: 1;
min-width: 0; min-width: 0;
cursor: var(--pointer);
color: ${(props) => props.theme.text}; color: ${(props) => props.theme.text};
font-size: 15px; font-size: 15px;
height: 24px; height: 24px;

View File

@@ -30,7 +30,7 @@ const RealButton = styled(ActionButton)<RealProps>`
height: 32px; height: 32px;
text-decoration: none; text-decoration: none;
flex-shrink: 0; flex-shrink: 0;
cursor: pointer; cursor: var(--pointer);
user-select: none; user-select: none;
appearance: none !important; appearance: none !important;

View File

@@ -98,7 +98,7 @@ const Item = styled.div<{ active?: boolean }>`
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
cursor: pointer; cursor: var(--pointer);
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;

View File

@@ -139,7 +139,7 @@ export const MenuAnchorCSS = css<MenuAnchorProps>`
color: ${props.theme.white}; color: ${props.theme.white};
background: ${props.dangerous ? props.theme.danger : props.theme.primary}; background: ${props.dangerous ? props.theme.danger : props.theme.primary};
box-shadow: none; box-shadow: none;
cursor: pointer; cursor: var(--pointer);
svg { svg {
fill: ${props.theme.white}; fill: ${props.theme.white};

View File

@@ -236,6 +236,7 @@ const DocumentLink = styled(Link)<{
width: 100%; width: 100%;
height: 100%; height: 100%;
border-radius: 8px; border-radius: 8px;
cursor: var(--pointer);
background: ${(props) => props.theme.background}; background: ${(props) => props.theme.background};
transition: transform 50ms ease-in-out; transition: transform 50ms ease-in-out;
border: 1px solid ${(props) => props.theme.inputBorder}; border: 1px solid ${(props) => props.theme.inputBorder};

View File

@@ -201,6 +201,7 @@ const DocumentLink = styled(Link)<{
border-radius: 8px; border-radius: 8px;
max-height: 50vh; max-height: 50vh;
width: calc(100vw - 8px); width: calc(100vw - 8px);
cursor: var(--pointer);
&:focus-visible { &:focus-visible {
outline: none; outline: none;

View File

@@ -69,7 +69,7 @@ const More = styled.div<{ size: number }>`
const Avatars = styled(Flex)` const Avatars = styled(Flex)`
align-items: center; align-items: center;
flex-direction: row-reverse; flex-direction: row-reverse;
cursor: pointer; cursor: var(--pointer);
`; `;
export default observer(Facepile); export default observer(Facepile);

View File

@@ -102,7 +102,7 @@ const Image = styled(Flex)`
const Title = styled.span` const Title = styled.span`
&:hover { &:hover {
text-decoration: underline; text-decoration: underline;
cursor: pointer; cursor: var(--pointer);
} }
`; `;

View File

@@ -143,7 +143,7 @@ const Title = styled("div")`
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: var(--pointer);
min-width: 0; min-width: 0;
${breakpoint("tablet")` ${breakpoint("tablet")`

View File

@@ -50,7 +50,7 @@ function HoverPreviewDocument({ url, children }: Props) {
} }
const Content = styled(Link)` const Content = styled(Link)`
cursor: pointer; cursor: var(--pointer);
`; `;
const Heading = styled.h2` const Heading = styled.h2`

View File

@@ -288,7 +288,7 @@ const Positioner = styled(Position)`
color: ${(props) => props.theme.white}; color: ${(props) => props.theme.white};
background: ${(props) => props.theme.primary}; background: ${(props) => props.theme.primary};
box-shadow: none; box-shadow: none;
cursor: pointer; cursor: var(--pointer);
svg { svg {
fill: ${(props) => props.theme.white}; fill: ${(props) => props.theme.white};

View File

@@ -87,7 +87,7 @@ const Wrapper = styled.a<{
border-bottom: 0; border-bottom: 0;
} }
cursor: ${({ to }) => (to ? "pointer" : "default")}; cursor: ${({ to }) => (to ? "var(--pointer)" : "default")};
`; `;
const Image = styled(Flex)` const Image = styled(Flex)`

View File

@@ -27,7 +27,7 @@ const NudeButton = styled(ActionButton).attrs((props: Props) => ({
line-height: 0; line-height: 0;
border: 0; border: 0;
padding: 0; padding: 0;
cursor: pointer; cursor: var(--pointer);
user-select: none; user-select: none;
color: inherit; color: inherit;
`; `;

View File

@@ -83,6 +83,7 @@ const DocumentLink = styled(Link)<{
align-items: center; align-items: center;
padding: 6px 12px; padding: 6px 12px;
max-height: 50vh; max-height: 50vh;
cursor: var(--pointer);
&:not(:last-child) { &:not(:last-child) {
margin-bottom: 4px; margin-bottom: 4px;

View File

@@ -80,7 +80,7 @@ const Button = styled.button`
&:not(:disabled):hover, &:not(:disabled):hover,
&:not(:disabled):active { &:not(:disabled):active {
color: ${(props) => props.theme.textSecondary}; color: ${(props) => props.theme.textSecondary};
cursor: pointer; cursor: var(--pointer);
} }
`; `;

View File

@@ -68,7 +68,7 @@ const Wrapper = styled(Flex)<{ minHeight: number }>`
text-align: left; text-align: left;
overflow: hidden; overflow: hidden;
user-select: none; user-select: none;
cursor: pointer; cursor: var(--pointer);
&:active, &:active,
&:hover, &:hover,

View File

@@ -179,7 +179,7 @@ const Link = styled(NavLink)<{
color: ${(props) => color: ${(props) =>
props.$isActiveDrop ? props.theme.white : props.theme.sidebarText}; props.$isActiveDrop ? props.theme.white : props.theme.sidebarText};
font-size: 16px; font-size: 16px;
cursor: pointer; cursor: var(--pointer);
overflow: hidden; overflow: hidden;
${(props) => ${(props) =>

View File

@@ -47,7 +47,7 @@ export const ToggleButton = styled.button<{ $direction?: "left" | "right" }>`
${breakpoint("tablet")` ${breakpoint("tablet")`
pointer-events: all; pointer-events: all;
cursor: pointer; cursor: var(--pointer);
`} `}
@media (hover: none) { @media (hover: none) {

View File

@@ -86,7 +86,7 @@ const Input = styled.label<{ width: number; height: number }>`
const Slider = styled.span<{ width: number; height: number }>` const Slider = styled.span<{ width: number; height: number }>`
position: absolute; position: absolute;
cursor: pointer; cursor: var(--pointer);
top: 0; top: 0;
left: 0; left: 0;
right: 0; right: 0;

View File

@@ -8,7 +8,7 @@ import useMediaQuery from "~/hooks/useMediaQuery";
import useStores from "~/hooks/useStores"; import useStores from "~/hooks/useStores";
const Theme: React.FC = ({ children }) => { const Theme: React.FC = ({ children }) => {
const { ui } = useStores(); const { auth, ui } = useStores();
const resolvedTheme = ui.resolvedTheme === "dark" ? dark : light; const resolvedTheme = ui.resolvedTheme === "dark" ? dark : light;
const resolvedMobileTheme = const resolvedMobileTheme =
ui.resolvedTheme === "dark" ? darkMobile : lightMobile; ui.resolvedTheme === "dark" ? darkMobile : lightMobile;
@@ -27,7 +27,9 @@ const Theme: React.FC = ({ children }) => {
return ( return (
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<> <>
<GlobalStyles /> <GlobalStyles
useCursorPointer={auth.user?.preferences?.useCursorPointer !== false}
/>
{children} {children}
</> </>
</ThemeProvider> </ThemeProvider>

View File

@@ -76,7 +76,7 @@ const MenuItem = styled.button<{
line-height: 1; line-height: 1;
width: 100%; width: 100%;
height: 36px; height: 36px;
cursor: pointer; cursor: var(--pointer);
border: none; border: none;
opacity: ${(props) => (props.disabled ? ".5" : "1")}; opacity: ${(props) => (props.disabled ? ".5" : "1")};
color: ${(props) => color: ${(props) =>

View File

@@ -61,7 +61,7 @@ const ListItem = styled.li<{
text-decoration: none; text-decoration: none;
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
cursor: pointer; cursor: var(--pointer);
user-select: none; user-select: none;
line-height: ${(props) => (props.compact ? "inherit" : "1.2")}; line-height: ${(props) => (props.compact ? "inherit" : "1.2")};
height: ${(props) => (props.compact ? "28px" : "auto")}; height: ${(props) => (props.compact ? "28px" : "auto")};

View File

@@ -7,7 +7,7 @@ export default styled.button<Props>`
flex: 0; flex: 0;
width: 24px; width: 24px;
height: 24px; height: 24px;
cursor: pointer; cursor: var(--pointer);
border: none; border: none;
background: none; background: none;
transition: opacity 100ms ease-in-out; transition: opacity 100ms ease-in-out;

View File

@@ -26,7 +26,9 @@ class User extends ParanoidModel {
@observable @observable
language: string; language: string;
preferences: UserPreferences | null | undefined; @Field
@observable
preferences: UserPreferences | null;
email: string; email: string;

View File

@@ -27,6 +27,7 @@ const DocumentLink = styled(Link)`
min-width: 100%; min-width: 100%;
overflow: hidden; overflow: hidden;
position: relative; position: relative;
cursor: var(--pointer);
&:${hover}, &:${hover},
&:active, &:active,

View File

@@ -89,6 +89,7 @@ const RecentSearch = styled(Link)`
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
color: ${(props) => props.theme.textSecondary}; color: ${(props) => props.theme.textSecondary};
cursor: var(--pointer);
padding: 1px 4px; padding: 1px 4px;
border-radius: 4px; border-radius: 4px;

View File

@@ -83,6 +83,20 @@ function Preferences() {
ariaLabel={t("Language")} ariaLabel={t("Language")}
/> />
</SettingRow> </SettingRow>
<SettingRow
name="useCursorPointer"
label={t("Use pointer cursor")}
description={t(
"Show a hand cursor when hovering over interactive elements."
)}
>
<Switch
id="useCursorPointer"
name="useCursorPointer"
checked={user.preferences?.useCursorPointer !== false}
onChange={handlePreferenceChange}
/>
</SettingRow>
<SettingRow <SettingRow
border={false} border={false}
name="rememberLastPath" name="rememberLastPath"

View File

@@ -116,7 +116,7 @@ const DropzoneContainer = styled.div<{
padding: 52px; padding: 52px;
text-align: center; text-align: center;
font-size: 15px; font-size: 15px;
cursor: pointer; cursor: var(--pointer);
opacity: ${(props) => (props.$disabled ? 0.5 : 1)}; opacity: ${(props) => (props.$disabled ? 0.5 : 1)};
&:hover { &:hover {

View File

@@ -49,7 +49,7 @@ const ImageBox = styled(Flex)`
bottom: 0; bottom: 0;
left: 0; left: 0;
opacity: 0; opacity: 0;
cursor: pointer; cursor: var(--pointer);
transition: all 250ms; transition: all 250ms;
} }

View File

@@ -158,7 +158,7 @@ const RangeInput = styled.input`
width: 300px; width: 300px;
margin-bottom: 30px; margin-bottom: 30px;
height: 4px; height: 4px;
cursor: pointer; cursor: var(--pointer);
color: inherit; color: inherit;
border-radius: 99999px; border-radius: 99999px;
background-color: #dee1e3; background-color: #dee1e3;
@@ -170,7 +170,7 @@ const RangeInput = styled.input`
width: 16px; width: 16px;
border-radius: 50%; border-radius: 50%;
background: ${(props) => props.theme.text}; background: ${(props) => props.theme.text};
cursor: pointer; cursor: var(--pointer);
} }
&:focus { &:focus {

View File

@@ -43,7 +43,7 @@ const UserListItem = ({ user, showMenu }: Props) => {
const Title = styled.span` const Title = styled.span`
&:hover { &:hover {
text-decoration: underline; text-decoration: underline;
cursor: pointer; cursor: var(--pointer);
} }
`; `;

View File

@@ -190,12 +190,12 @@ router.post("users.update", auth(), async (ctx) => {
} }
if (preferences) { if (preferences) {
assertKeysIn(preferences, UserPreference); assertKeysIn(preferences, UserPreference);
if (has(preferences, UserPreference.RememberLastPath)) {
assertBoolean(preferences.rememberLastPath); for (const value of Object.values(UserPreference)) {
user.setPreference( if (has(preferences, value)) {
UserPreference.RememberLastPath, assertBoolean(preferences[value]);
preferences.rememberLastPath user.setPreference(value, preferences[value]);
); }
} }
} }
await user.save(); await user.save();

View File

@@ -347,7 +347,7 @@ h6:not(.placeholder):before {
display: inline-block; display: inline-block;
color: ${props.theme.text}; color: ${props.theme.text};
opacity: .75; opacity: .75;
cursor: pointer; cursor: var(--pointer);
background: none; background: none;
outline: none; outline: none;
border: 0; border: 0;
@@ -673,7 +673,7 @@ ul.checkbox_list li::before {
ul.checkbox_list li .checkbox { ul.checkbox_list li .checkbox {
display: inline-block; display: inline-block;
cursor: pointer; cursor: var(--pointer);
pointer-events: ${ pointer-events: ${
props.readOnly && !props.readOnlyWriteCheckboxes ? "none" : "initial" props.readOnly && !props.readOnlyWriteCheckboxes ? "none" : "initial"
}; };
@@ -797,7 +797,7 @@ mark {
font-weight: 500; font-weight: 500;
text-decoration: none; text-decoration: none;
flex-shrink: 0; flex-shrink: 0;
cursor: pointer; cursor: var(--pointer);
user-select: none; user-select: none;
appearance: none !important; appearance: none !important;
padding: 6px 8px; padding: 6px 8px;
@@ -1230,7 +1230,7 @@ table {
&:hover, &:hover,
&:focus { &:focus {
cursor: pointer; cursor: var(--pointer);
color: ${props.theme.text}; color: ${props.theme.text};
background: ${props.theme.secondaryBackground}; background: ${props.theme.secondaryBackground};
} }

View File

@@ -551,7 +551,7 @@ const Button = styled.button`
width: 24px; width: 24px;
height: 24px; height: 24px;
display: inline-block; display: inline-block;
cursor: pointer; cursor: var(--pointer);
opacity: 0; opacity: 0;
transition: opacity 100ms ease-in-out; transition: opacity 100ms ease-in-out;

View File

@@ -696,6 +696,8 @@
"Delete account": "Delete account", "Delete account": "Delete account",
"Language": "Language", "Language": "Language",
"Choose the interface language. Community translations are accepted though our <2>translation portal</2>.": "Choose the interface language. Community translations are accepted though our <2>translation portal</2>.", "Choose the interface language. Community translations are accepted though our <2>translation portal</2>.": "Choose the interface language. Community translations are accepted though our <2>translation portal</2>.",
"Use pointer cursor": "Use pointer cursor",
"Show a hand cursor when hovering over interactive elements.": "Show a hand cursor when hovering over interactive elements.",
"Remember previous location": "Remember previous location", "Remember previous location": "Remember previous location",
"Automatically return to the document you were last viewing when the app is re-opened.": "Automatically return to the document you were last viewing when the app is re-opened.", "Automatically return to the document you were last viewing when the app is re-opened.": "Automatically return to the document you were last viewing when the app is re-opened.",
"You may delete your account at any time, note that this is unrecoverable": "You may delete your account at any time, note that this is unrecoverable", "You may delete your account at any time, note that this is unrecoverable": "You may delete your account at any time, note that this is unrecoverable",

View File

@@ -2,7 +2,9 @@ import { createGlobalStyle } from "styled-components";
import styledNormalize from "styled-normalize"; import styledNormalize from "styled-normalize";
import { breakpoints, depths } from "."; import { breakpoints, depths } from ".";
export default createGlobalStyle` type Props = { useCursorPointer?: boolean };
export default createGlobalStyle<Props>`
${styledNormalize} ${styledNormalize}
* { * {
@@ -17,6 +19,7 @@ export default createGlobalStyle`
padding: 0; padding: 0;
print-color-adjust: exact; print-color-adjust: exact;
-webkit-print-color-adjust: exact; -webkit-print-color-adjust: exact;
--pointer: ${(props) => (props.useCursorPointer ? "pointer" : "default")};
} }
body, body,

View File

@@ -46,6 +46,7 @@ export type IntegrationSettings<T> = T extends IntegrationType.Embed
export enum UserPreference { export enum UserPreference {
RememberLastPath = "rememberLastPath", RememberLastPath = "rememberLastPath",
UseCursorPointer = "useCursorPointer",
} }
export type UserPreferences = { [key in UserPreference]?: boolean }; export type UserPreferences = { [key in UserPreference]?: boolean };