Skip to content

Commit

Permalink
feat: add description tooltips for variable axis
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Apr 29, 2023
1 parent 6f9a9c4 commit 232457b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 5 deletions.
22 changes: 22 additions & 0 deletions website/app/components/InfoTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ActionIcon, Tooltip } from '@mantine/core';

import { IconInfo } from '@/components/icons';

interface InfoTooltipProps {
label: string;
}
export const InfoTooltip = ({ label }: InfoTooltipProps) => {
return (
<Tooltip
multiline
width={240}
withArrow
transitionProps={{ duration: 200 }}
label={label}
>
<ActionIcon variant="transparent" color="gray" radius="xl">
<IconInfo height={18} />
</ActionIcon>
</Tooltip>
);
};
50 changes: 50 additions & 0 deletions website/app/components/icons/Info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useMantineTheme } from '@mantine/core';

import type { IconProps } from './types';

const IconInfo = ({ height, ...others }: IconProps) => {
const theme = useMantineTheme();
const stroke =
theme.colorScheme === 'dark' ? theme.colors.text[0] : theme.colors.text[1];

return (
<svg
height={height}
viewBox="0 0 20 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...others}
>
<g clip-path="url(#clip0_211_1023)">
<path
d="M10 18.3333C14.6024 18.3333 18.3333 14.6024 18.3333 9.99999C18.3333 5.39762 14.6024 1.66666 10 1.66666C5.39763 1.66666 1.66667 5.39762 1.66667 9.99999C1.66667 14.6024 5.39763 18.3333 10 18.3333Z"
stroke={stroke}
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M10 13.3333V10"
stroke={stroke}
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M10 6.66666H10.01"
stroke="#01112C"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</g>
<defs>
<clipPath id="clip0_211_1023">
<rect width="20" height="20" fill="white" />
</clipPath>
</defs>
</svg>
);
};

export { IconInfo };
1 change: 1 addition & 0 deletions website/app/components/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { IconEye } from './Eye';
export { IconGithub } from './Github';
export { IconGrid } from './Grid';
export { IconHorizontal } from './Horizontal';
export { IconInfo } from './Info';
export { IconList } from './List';
export { IconMoon } from './Moon';
export { IconRotate } from './Rotate';
Expand Down
28 changes: 23 additions & 5 deletions website/app/components/preview/VariableButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAtom } from 'jotai';
import { IconRotate } from '@/components/icons';
import type { AxesData, AxisRegistryAll, VariableData } from '@/utils/types';

import { InfoTooltip } from '../InfoTooltip';
import { variableAtom, variationAtom } from './atoms';

interface VariableButtonGroupProps {
Expand All @@ -23,6 +24,7 @@ interface VariableButtonProps {
tag: string;
label: string;
axes: AxesData;
description: string;
}

const useStyles = createStyles((theme) => ({
Expand Down Expand Up @@ -54,7 +56,12 @@ const useStyles = createStyles((theme) => ({
},
}));

const VariableButton = ({ tag, label, axes }: VariableButtonProps) => {
const VariableButton = ({
tag,
label,
axes,
description,
}: VariableButtonProps) => {
const { classes } = useStyles();
const [_, setVariation] = useAtom(variationAtom);
const [variableValue] = useAtom(variableAtom);
Expand All @@ -69,7 +76,12 @@ const VariableButton = ({ tag, label, axes }: VariableButtonProps) => {
return (
<Box className={classes.button}>
<Group position="apart" mb={3}>
<Text fz='sm' fw={400}>{label}</Text>
<Group align='center' spacing={2}>
<Text fz="sm" fw={400}>
{label} <span>({tag})</span>
</Text>
<InfoTooltip label={description} />
</Group>
<ActionIcon onClick={resetVariationAtom} variant="transparent" mr={-4}>
<IconRotate height={16} />
</ActionIcon>
Expand All @@ -84,8 +96,8 @@ const VariableButton = ({ tag, label, axes }: VariableButtonProps) => {
value={variableValue[tag] ?? Number(axes.default)}
/>
<Group position="apart" px={3} mt={4}>
<Text fz='sm'>{axes.min}</Text>
<Text fz='sm'>{axes.max}</Text>
<Text fz="sm">{axes.min}</Text>
<Text fz="sm">{axes.max}</Text>
</Group>
</Box>
);
Expand All @@ -98,7 +110,13 @@ const VariableButtonsGroup = ({
return (
<>
{Object.keys(variable).map((key) => (
<VariableButton key={key} tag={key} label={axisRegistry[key].name} axes={variable[key]} />
<VariableButton
key={key}
tag={key}
label={axisRegistry[key].name}
description={axisRegistry[key].description}
axes={variable[key]}
/>
))}
</>
);
Expand Down

0 comments on commit 232457b

Please sign in to comment.