Skip to content

Commit

Permalink
Merge pull request #240 from tchryssos/tc-sotww-updates
Browse files Browse the repository at this point in the history
Sotww updates
  • Loading branch information
tchryssos authored Sep 10, 2024
2 parents 722d6ea + b504c60 commit 55957f5
Show file tree
Hide file tree
Showing 24 changed files with 378 additions and 203 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@auth0/nextjs-auth0": "^1.9.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@floating-ui/react": "^0.26.23",
"@mui/base": "5.0.0-beta.4",
"@playwright/test": "^1.35.0",
"@prisma/client": "^4.15.0",
Expand Down
43 changes: 0 additions & 43 deletions src/components/Divider.tsx

This file was deleted.

88 changes: 88 additions & 0 deletions src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import styled from '@emotion/styled';
import {
autoUpdate,
flip,
offset,
shift,
useDismiss,
useFloating,
useFocus,
useHover,
useInteractions,
useRole,
} from '@floating-ui/react';
import { PropsWithChildren, useState } from 'react';

import { pxToRem } from '~/logic/utils/styles/pxToRem';

import { Box } from './box/Box';

interface TooltipProps {
id: string;
tipText: string;
isLabeled: boolean;
}

const Target = styled.div``;

const Tip = styled.span`
background: ${({ theme }) => theme.colors.background};
color: ${({ theme }) => theme.colors.text};
width: ${pxToRem(200)};
padding: ${({ theme }) => theme.spacing[8]};
border: 1px solid ${({ theme }) => theme.colors.text};
`;

export function Tooltip({
id,
children,
tipText,
isLabeled,
}: PropsWithChildren<TooltipProps>) {
const [show, setShow] = useState(false);
const { refs, floatingStyles, context } = useFloating({
open: show,
whileElementsMounted: autoUpdate,
onOpenChange: setShow,
middleware: [offset(10), flip(), shift()],
});

const hover = useHover(context, { move: false });
const focus = useFocus(context);
const dismiss = useDismiss(context);
const role = useRole(context, {
role: isLabeled ? 'tooltip' : 'label',
});

// Merge all the interactions into prop getters
const { getReferenceProps, getFloatingProps } = useInteractions([
hover,
focus,
dismiss,
role,
]);

return (
<Box position="relative">
{show && (
<Tip
id={id}
ref={refs.setFloating}
role="tooltip"
style={floatingStyles}
{...getFloatingProps()}
>
{tipText}
</Tip>
)}
<Target
aria-describedby={id}
ref={refs.setReference}
tabIndex={0}
{...getReferenceProps()}
>
{children}
</Target>
</Box>
);
}
37 changes: 37 additions & 0 deletions src/components/divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { pxToRem } from '~/logic/utils/styles/pxToRem';

import { Box } from '../box/Box';
import { DividerWrapper, Label, Segment } from './components';
import { DividerProps } from './types';

export function Divider({
color = 'text',
vertical,
className,
label,
}: DividerProps) {
if (vertical) {
return (
<Box
backgroundColor={color}
className={className}
height="100%"
width={pxToRem(1)}
/>
);
}

return (
<DividerWrapper center className={className}>
{label && (
<>
<Segment color={color} />
<Label as="p" variant="body">
{label}
</Label>
</>
)}
<Segment color={color} />
</DividerWrapper>
);
}
20 changes: 20 additions & 0 deletions src/components/divider/components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import styled from '@emotion/styled';

import { FlexBox } from '../box/FlexBox';
import { Text } from '../Text';
import { DividerProps } from './types';

export const DividerWrapper = styled(FlexBox)`
min-height: ${({ theme }) => theme.borderWidth[1]};
width: 100%;
`;

export const Segment = styled.div<Pick<DividerProps, 'color'>>`
width: 100%;
height: ${({ theme }) => theme.borderWidth[1]};
background-color: ${({ theme, color }) => theme.colors[color || 'text']};
`;

export const Label = styled(Text)`
padding: 0 ${({ theme }) => theme.spacing[16]};
`;
16 changes: 16 additions & 0 deletions src/components/divider/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Color } from '~/typings/theme';

type HorizDividerProps = {
label?: string;
vertical?: never | false;
};

type VerticalDividerProps = {
label?: never;
vertical: true;
};

export type DividerProps = {
color?: Color;
className?: string;
} & (HorizDividerProps | VerticalDividerProps);
2 changes: 1 addition & 1 deletion src/components/dropdowns/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MouseEventHandler, useState } from 'react';

import { FlexBox } from '../box/FlexBox';
import { TextButton } from '../buttons/TextButton';
import { Divider } from '../Divider';
import { Divider } from '../divider/Divider';
import { Link } from '../Link';
import { Pane } from '../Pane';
import { Text } from '../Text';
Expand Down
6 changes: 3 additions & 3 deletions src/components/formNav/SaveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export function SaveButton({
characterId = NEW_ID,
rulebookName,
}: SaveButtonProps) {
const [isSaving, setisSaving] = useState(false);
const [isSaving, setIsSaving] = useState(false);
const { addNotifications } = useContext(NotificationsContext);
const { getValues } = useFormContext();

const { push } = useRouter();

const onSave = async () => {
setisSaving(true);
setIsSaving(true);
try {
const resp = await saveCharacter({
id: characterId as number | typeof NEW_ID,
Expand Down Expand Up @@ -66,7 +66,7 @@ export function SaveButton({
),
]);
}
setisSaving(false);
setIsSaving(false);
};

return (
Expand Down
55 changes: 34 additions & 21 deletions src/components/nav/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import styled from '@emotion/styled';

import { HOME_ROUTE } from '~/constants/routing/client';
import { createUsersRoute } from '~/constants/routing/shared';
import { useBreakpointsLessThan } from '~/logic/hooks/useBreakpoints';
import {
useBreakpointsAtLeast,
useBreakpointsLessThan,
} from '~/logic/hooks/useBreakpoints';
import { pxToRem } from '~/logic/utils/styles/pxToRem';
import { getIconFromUser, getNameFromUser } from '~/logic/utils/user';
import { Spacing } from '~/typings/theme';
Expand All @@ -13,6 +16,7 @@ import { LogoAscii } from '../ascii/LogoAscii';
import { Box } from '../box/Box';
import { FlexBox } from '../box/FlexBox';
import { GridBox } from '../box/GridBox';
import { Divider } from '../divider/Divider';
import { DropdownMenuProps } from '../dropdowns/DropdownMenu';
import { ProfileDropdown } from '../dropdowns/ProfileDropdown';
import { RpgIcon } from '../icons/RpgIcon';
Expand Down Expand Up @@ -74,6 +78,11 @@ const UserName = styled(Text)`
white-space: nowrap;
`;

const VertDivider = styled(Divider)`
align-self: stretch;
height: unset;
`;

interface NavBarProps {
title: string;
setIconPortalNode: (node: HTMLDivElement) => void;
Expand All @@ -88,6 +97,7 @@ export function NavBar({
dropdownMenuItems,
}: NavBarProps) {
const isXxs = useBreakpointsLessThan('xs');
const atLeastMd = useBreakpointsAtLeast('md');
const flexGap = isXxs ? 8 : 16;
const { user } = useUser();
const userName = getNameFromUser(user as StrictSessionUser);
Expand All @@ -110,27 +120,30 @@ export function NavBar({
</LogoTitleBox>
<FlexBox alignItems="center" gap={flexGap}>
<Portal flexGap={flexGap} ref={setIconPortalNode} />
{userName && !isXxs && (
<Link
href={createUsersRoute((user as StrictSessionUser).id)}
isInternal
>
<GridBox
alignItems="center"
gap={8}
gridTemplateColumns="auto 1fr"
maxWidth={pxToRem(200)}
{userName && atLeastMd && (
<>
<VertDivider color="accentLight" vertical />
<Link
href={createUsersRoute((user as StrictSessionUser).id)}
isInternal
>
<Box height={pxToRem(18)} width={pxToRem(18)}>
<RpgIcon
iconIndex={getIconFromUser(user as StrictSessionUser)}
/>
</Box>
<UserName as="p" overflow="hidden" textOverflow="ellipsis">
{userName}
</UserName>
</GridBox>
</Link>
<GridBox
alignItems="center"
gap={8}
gridTemplateColumns="auto 1fr"
maxWidth={pxToRem(200)}
>
<Box height={pxToRem(18)} width={pxToRem(18)}>
<RpgIcon
iconIndex={getIconFromUser(user as StrictSessionUser)}
/>
</Box>
<UserName as="p" overflow="hidden" textOverflow="ellipsis">
{userName}
</UserName>
</GridBox>
</Link>
</>
)}
<ProfileDropdown dropdownMenuItems={dropdownMenuItems} />
</FlexBox>
Expand Down
33 changes: 0 additions & 33 deletions src/components/pills/PropertyPills.tsx

This file was deleted.

Loading

0 comments on commit 55957f5

Please sign in to comment.