Introduce new border radius variables for stable theming.

This commit is contained in:
LambdAurora 2021-08-30 23:39:02 +02:00
parent d368820aeb
commit 1d42f0a60a
No known key found for this signature in database
GPG key ID: F3600344819E21A5
5 changed files with 20 additions and 7 deletions

View file

@ -51,6 +51,12 @@ export default observer(
} }
} }
// The border radius of the channel icon, if it's a server-channel it should be square (undefined).
let borderRadius;
if (!isServerChannel) {
borderRadius = "--border-radius-half";
}
return ( return (
// ! TODO: replace fallback with <picture /> + <source /> // ! TODO: replace fallback with <picture /> + <source />
<ImageIconBase <ImageIconBase
@ -59,7 +65,7 @@ export default observer(
height={size} height={size}
loading="lazy" loading="lazy"
aria-hidden="true" aria-hidden="true"
square={isServerChannel} {...borderRadius}
src={iconURL ?? fallback} src={iconURL ?? fallback}
/> />
); );

View file

@ -11,7 +11,10 @@ export interface IconBaseProps<T> {
} }
interface IconModifiers { interface IconModifiers {
square?: boolean; /**
* If this is undefined or null then the icon defaults to square, else uses the CSS variable given.
*/
borderRadius?: string;
hover?: boolean; hover?: boolean;
} }
@ -24,9 +27,9 @@ export default styled.svg<IconModifiers>`
object-fit: cover; object-fit: cover;
${(props) => ${(props) =>
!props.square && props.borderRadius &&
css` css`
border-radius: var(--border-radius-half); border-radius: var(${props.borderRadius});
`} `}
} }
@ -44,9 +47,9 @@ export const ImageIconBase = styled.img<IconModifiers>`
object-fit: cover; object-fit: cover;
${(props) => ${(props) =>
!props.square && props.borderRadius &&
css` css`
border-radius: var(--border-radius-half); border-radius: var(${props.borderRadius});
`} `}
${(props) => ${(props) =>

View file

@ -59,6 +59,7 @@ export default observer(
{...imgProps} {...imgProps}
width={size} width={size}
height={size} height={size}
borderRadius="--border-radius-server-icon"
src={iconURL} src={iconURL}
loading="lazy" loading="lazy"
aria-hidden="true" aria-hidden="true"

View file

@ -8,7 +8,7 @@ import styled, { css } from "styled-components";
import { useContext } from "preact/hooks"; import { useContext } from "preact/hooks";
import { ThemeContext } from "../../../context/Theme"; import { ThemeContext } from "../../../context/Theme";
import { AppContext, useClient } from "../../../context/revoltjs/RevoltClient"; import { useClient } from "../../../context/revoltjs/RevoltClient";
import IconBase, { IconBaseProps } from "../IconBase"; import IconBase, { IconBaseProps } from "../IconBase";
import fallback from "../assets/user.png"; import fallback from "../assets/user.png";
@ -104,6 +104,7 @@ export default observer(
width={size} width={size}
height={size} height={size}
hover={hover} hover={hover}
borderRadius="--border-radius-user-profile-picture"
aria-hidden="true" aria-hidden="true"
viewBox="0 0 32 32"> viewBox="0 0 32 32">
<foreignObject <foreignObject

View file

@ -21,6 +21,8 @@
--app-height: 100vh; --app-height: 100vh;
--border-radius: 6px; --border-radius: 6px;
--border-radius-half: 50%; --border-radius-half: 50%;
--border-radius-user-profile-picture: var(--border-radius-half);
--border-radius-server-icon: var(--border-radius-half);
--input-border-width: 2px; --input-border-width: 2px;
--textarea-padding: 16px; --textarea-padding: 16px;