mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
[UI] Stylish text tweak (#9336)
* Update <StylishText> - Re-enable gradient - Based on selected highlight color * Refactor UI * Do not require size prop * Memoize
This commit is contained in:
parent
662a0b275e
commit
cfd83a3d62
@ -1,18 +1,58 @@
|
|||||||
import { Text, useMantineTheme } from '@mantine/core';
|
import {
|
||||||
|
type MantineSize,
|
||||||
|
Text,
|
||||||
|
darken,
|
||||||
|
getThemeColor,
|
||||||
|
lighten,
|
||||||
|
useMantineColorScheme,
|
||||||
|
useMantineTheme
|
||||||
|
} from '@mantine/core';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { useLocalState } from '../../states/LocalState';
|
||||||
|
|
||||||
import * as classes from '../../main.css';
|
// Hook that memoizes the gradient color based on the primary color of the theme
|
||||||
|
const useThematicGradient = () => {
|
||||||
|
const { usertheme } = useLocalState();
|
||||||
|
const theme = useMantineTheme();
|
||||||
|
const colorScheme = useMantineColorScheme();
|
||||||
|
|
||||||
|
const primary = useMemo(() => {
|
||||||
|
return getThemeColor(usertheme.primaryColor, theme);
|
||||||
|
}, [usertheme.primaryColor, theme]);
|
||||||
|
|
||||||
|
const secondary = useMemo(() => {
|
||||||
|
let secondary = primary;
|
||||||
|
if (colorScheme.colorScheme == 'dark') {
|
||||||
|
secondary = lighten(primary, 0.3);
|
||||||
|
} else {
|
||||||
|
secondary = darken(primary, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
return secondary;
|
||||||
|
}, [usertheme, colorScheme, primary]);
|
||||||
|
|
||||||
|
return useMemo(() => {
|
||||||
|
return { primary, secondary };
|
||||||
|
}, [primary, secondary]);
|
||||||
|
};
|
||||||
|
|
||||||
|
// A stylish text component that uses the primary color of the theme
|
||||||
export function StylishText({
|
export function StylishText({
|
||||||
children,
|
children,
|
||||||
size = 'md'
|
size
|
||||||
}: Readonly<{
|
}: Readonly<{
|
||||||
children: JSX.Element | string;
|
children: JSX.Element | string;
|
||||||
size?: string;
|
size?: MantineSize;
|
||||||
}>) {
|
}>) {
|
||||||
const theme = useMantineTheme();
|
const { primary, secondary } = useThematicGradient();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Text size={size} className={classes.signText} c={theme.primaryColor}>
|
<Text
|
||||||
|
fw={700}
|
||||||
|
size={size ?? 'xl'}
|
||||||
|
variant='gradient'
|
||||||
|
gradient={{ from: primary.toString(), to: secondary.toString() }}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
|
@ -6,6 +6,7 @@ import type { To } from 'react-router-dom';
|
|||||||
|
|
||||||
import type { UiSizeType } from '../../defaults/formatters';
|
import type { UiSizeType } from '../../defaults/formatters';
|
||||||
import { useLocalState } from '../../states/LocalState';
|
import { useLocalState } from '../../states/LocalState';
|
||||||
|
import { StylishText } from '../items/StylishText';
|
||||||
import * as classes from './DetailDrawer.css';
|
import * as classes from './DetailDrawer.css';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,9 +67,7 @@ function DetailDrawerComponent({
|
|||||||
<IconChevronLeft />
|
<IconChevronLeft />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
)}
|
)}
|
||||||
<Text size='xl' fw={600} variant='gradient'>
|
<StylishText size='xl'>{title}</StylishText>
|
||||||
{title}
|
|
||||||
</Text>
|
|
||||||
</Group>
|
</Group>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -112,11 +112,6 @@ export const tab = style({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const signText = style({
|
|
||||||
fontSize: 'xl',
|
|
||||||
fontWeight: 700
|
|
||||||
});
|
|
||||||
|
|
||||||
export const error = style({
|
export const error = style({
|
||||||
backgroundColor: vars.colors.gray[0],
|
backgroundColor: vars.colors.gray[0],
|
||||||
color: vars.colors.red[6]
|
color: vars.colors.red[6]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Trans, t } from '@lingui/macro';
|
import { Trans, t } from '@lingui/macro';
|
||||||
import { Badge, Group, Stack, Table, Title } from '@mantine/core';
|
import { Badge, Group, Stack, Table } from '@mantine/core';
|
||||||
import { IconEdit, IconKey, IconUser } from '@tabler/icons-react';
|
import { IconEdit, IconKey, IconUser } from '@tabler/icons-react';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
@ -8,6 +8,7 @@ import { ActionButton } from '../../../../components/buttons/ActionButton';
|
|||||||
import { YesNoUndefinedButton } from '../../../../components/buttons/YesNoButton';
|
import { YesNoUndefinedButton } from '../../../../components/buttons/YesNoButton';
|
||||||
import type { ApiFormFieldSet } from '../../../../components/forms/fields/ApiFormField';
|
import type { ApiFormFieldSet } from '../../../../components/forms/fields/ApiFormField';
|
||||||
import { ActionDropdown } from '../../../../components/items/ActionDropdown';
|
import { ActionDropdown } from '../../../../components/items/ActionDropdown';
|
||||||
|
import { StylishText } from '../../../../components/items/StylishText';
|
||||||
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
|
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
|
||||||
import { useEditApiFormModal } from '../../../../hooks/UseForm';
|
import { useEditApiFormModal } from '../../../../hooks/UseForm';
|
||||||
import { useUserState } from '../../../../states/UserState';
|
import { useUserState } from '../../../../states/UserState';
|
||||||
@ -98,9 +99,9 @@ export function AccountDetailPanel() {
|
|||||||
{editProfile.modal}
|
{editProfile.modal}
|
||||||
<Stack gap='xs'>
|
<Stack gap='xs'>
|
||||||
<Group justify='space-between'>
|
<Group justify='space-between'>
|
||||||
<Title order={3}>
|
<StylishText size='lg'>
|
||||||
<Trans>Account Details</Trans>
|
<Trans>Account Details</Trans>
|
||||||
</Title>
|
</StylishText>
|
||||||
<ActionDropdown
|
<ActionDropdown
|
||||||
tooltip={t`Account Actions`}
|
tooltip={t`Account Actions`}
|
||||||
icon={<IconUser />}
|
icon={<IconUser />}
|
||||||
@ -125,9 +126,9 @@ export function AccountDetailPanel() {
|
|||||||
{renderDetailTable(accountDetailFields)}
|
{renderDetailTable(accountDetailFields)}
|
||||||
|
|
||||||
<Group justify='space-between'>
|
<Group justify='space-between'>
|
||||||
<Title order={3}>
|
<StylishText size='lg'>
|
||||||
<Trans>Profile Details</Trans>
|
<Trans>Profile Details</Trans>
|
||||||
</Title>
|
</StylishText>
|
||||||
<ActionButton
|
<ActionButton
|
||||||
text={t`Edit Profile`}
|
text={t`Edit Profile`}
|
||||||
icon={<IconEdit />}
|
icon={<IconEdit />}
|
||||||
|
@ -15,7 +15,6 @@ import {
|
|||||||
Table,
|
Table,
|
||||||
Text,
|
Text,
|
||||||
TextInput,
|
TextInput,
|
||||||
Title,
|
|
||||||
Tooltip
|
Tooltip
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useDisclosure } from '@mantine/hooks';
|
import { useDisclosure } from '@mantine/hooks';
|
||||||
@ -467,14 +466,14 @@ function MfaSection() {
|
|||||||
title={t`Recovery Codes`}
|
title={t`Recovery Codes`}
|
||||||
centered
|
centered
|
||||||
>
|
>
|
||||||
<Title order={3}>
|
<StylishText size='lg'>
|
||||||
<Trans>Unused Codes</Trans>
|
<Trans>Unused Codes</Trans>
|
||||||
</Title>
|
</StylishText>
|
||||||
<Code>{recoveryCodes?.unused_codes?.join('\n')}</Code>
|
<Code>{recoveryCodes?.unused_codes?.join('\n')}</Code>
|
||||||
|
|
||||||
<Title order={3}>
|
<StylishText size='lg'>
|
||||||
<Trans>Used Codes</Trans>
|
<Trans>Used Codes</Trans>
|
||||||
</Title>
|
</StylishText>
|
||||||
<Code>{recoveryCodes?.used_codes?.join('\n')}</Code>
|
<Code>{recoveryCodes?.used_codes?.join('\n')}</Code>
|
||||||
</Modal>
|
</Modal>
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
|
@ -11,7 +11,6 @@ import {
|
|||||||
Select,
|
Select,
|
||||||
Slider,
|
Slider,
|
||||||
Table,
|
Table,
|
||||||
Title,
|
|
||||||
useMantineTheme
|
useMantineTheme
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { IconRestore } from '@tabler/icons-react';
|
import { IconRestore } from '@tabler/icons-react';
|
||||||
@ -19,6 +18,7 @@ import { useState } from 'react';
|
|||||||
|
|
||||||
import { ColorToggle } from '../../../../components/items/ColorToggle';
|
import { ColorToggle } from '../../../../components/items/ColorToggle';
|
||||||
import { LanguageSelect } from '../../../../components/items/LanguageSelect';
|
import { LanguageSelect } from '../../../../components/items/LanguageSelect';
|
||||||
|
import { StylishText } from '../../../../components/items/StylishText';
|
||||||
import { SizeMarks } from '../../../../defaults/defaults';
|
import { SizeMarks } from '../../../../defaults/defaults';
|
||||||
import { IS_DEV } from '../../../../main';
|
import { IS_DEV } from '../../../../main';
|
||||||
import { useLocalState } from '../../../../states/LocalState';
|
import { useLocalState } from '../../../../states/LocalState';
|
||||||
@ -57,9 +57,9 @@ export function UserTheme({ height }: Readonly<{ height: number }>) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Container w='100%' mih={height} p={0}>
|
<Container w='100%' mih={height} p={0}>
|
||||||
<Title order={3}>
|
<StylishText size='lg'>
|
||||||
<Trans>Display Settings</Trans>
|
<Trans>Display Settings</Trans>
|
||||||
</Title>
|
</StylishText>
|
||||||
<Table>
|
<Table>
|
||||||
<Table.Tbody>
|
<Table.Tbody>
|
||||||
<Table.Tr>
|
<Table.Tr>
|
||||||
|
@ -11,8 +11,7 @@ import {
|
|||||||
List,
|
List,
|
||||||
LoadingOverlay,
|
LoadingOverlay,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text
|
||||||
Title
|
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { notifications } from '@mantine/notifications';
|
import { notifications } from '@mantine/notifications';
|
||||||
import { IconCheck, IconRefresh } from '@tabler/icons-react';
|
import { IconCheck, IconRefresh } from '@tabler/icons-react';
|
||||||
@ -248,9 +247,8 @@ function MachineDrawer({
|
|||||||
<Group justify='space-between'>
|
<Group justify='space-between'>
|
||||||
<Group>
|
<Group>
|
||||||
{machine && <MachineStatusIndicator machine={machine} />}
|
{machine && <MachineStatusIndicator machine={machine} />}
|
||||||
<Title order={4}>{machine?.name}</Title>
|
<StylishText size='md'>{machine?.name ?? t`Machine`}</StylishText>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
{machine?.restart_required && (
|
{machine?.restart_required && (
|
||||||
<Badge color='red'>
|
<Badge color='red'>
|
||||||
|
@ -85,9 +85,9 @@ function MachineTypeDrawer({
|
|||||||
<>
|
<>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Group wrap='nowrap'>
|
<Group wrap='nowrap'>
|
||||||
<Title order={4}>
|
<StylishText size='md'>
|
||||||
{machineType ? machineType.name : machineTypeSlug}
|
{machineType ? machineType.name : machineTypeSlug}
|
||||||
</Title>
|
</StylishText>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
{!machineType && (
|
{!machineType && (
|
||||||
|
@ -6,8 +6,7 @@ import {
|
|||||||
Pill,
|
Pill,
|
||||||
PillGroup,
|
PillGroup,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text
|
||||||
Title
|
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
@ -15,6 +14,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import { AddItemButton } from '../../components/buttons/AddItemButton';
|
import { AddItemButton } from '../../components/buttons/AddItemButton';
|
||||||
import AdminButton from '../../components/buttons/AdminButton';
|
import AdminButton from '../../components/buttons/AdminButton';
|
||||||
import { EditApiForm } from '../../components/forms/ApiForm';
|
import { EditApiForm } from '../../components/forms/ApiForm';
|
||||||
|
import { StylishText } from '../../components/items/StylishText';
|
||||||
import { DetailDrawer } from '../../components/nav/DetailDrawer';
|
import { DetailDrawer } from '../../components/nav/DetailDrawer';
|
||||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||||
import { ModelType } from '../../enums/ModelType';
|
import { ModelType } from '../../enums/ModelType';
|
||||||
@ -112,9 +112,9 @@ export function GroupDrawer({
|
|||||||
id={`group-detail-drawer-${id}`}
|
id={`group-detail-drawer-${id}`}
|
||||||
/>
|
/>
|
||||||
<Group justify='space-between'>
|
<Group justify='space-between'>
|
||||||
<Title order={5}>
|
<StylishText size='md'>
|
||||||
<Trans>Permission set</Trans>
|
<Trans>Permission set</Trans>
|
||||||
</Title>
|
</StylishText>
|
||||||
<AdminButton model={ModelType.group} id={instance.pk} />
|
<AdminButton model={ModelType.group} id={instance.pk} />
|
||||||
</Group>
|
</Group>
|
||||||
<Group>{permissionsAccordion}</Group>
|
<Group>{permissionsAccordion}</Group>
|
||||||
|
@ -250,7 +250,7 @@ export function UserTable() {
|
|||||||
// Table Actions - Add New User
|
// Table Actions - Add New User
|
||||||
const newUser = useCreateApiFormModal({
|
const newUser = useCreateApiFormModal({
|
||||||
url: ApiEndpoints.user_list,
|
url: ApiEndpoints.user_list,
|
||||||
title: t`Add user`,
|
title: t`Add User`,
|
||||||
fields: {
|
fields: {
|
||||||
username: {},
|
username: {},
|
||||||
email: {},
|
email: {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user