Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to VuiOptionsList, VuiFlexItem, VuiButtonTertiary, and VuiAccountMenu #62

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/docs/pages/accountMenu/AccountMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react";
import { VuiAccountMenu, VuiButtonSecondary, VuiIcon, VuiOptionsList } from "../../../lib";
import { BiSolidUser } from "react-icons/bi";

Expand All @@ -7,8 +8,12 @@ const options = [
];

export const AccountMenu = () => {
const [isOpen, setIsOpen] = useState(false);

return (
<VuiAccountMenu
isOpen={isOpen}
setIsOpen={setIsOpen}
button={
<VuiButtonSecondary
color="accent"
Expand Down
7 changes: 3 additions & 4 deletions src/lib/components/accountMenu/AccountMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useState } from "react";
import { VuiPopover } from "../popover/Popover";

type AccountMenuInfo = Array<{
Expand All @@ -7,14 +6,14 @@ type AccountMenuInfo = Array<{
}>;

type Props = {
isOpen: boolean;
setIsOpen: (isOpen: boolean) => void;
button: React.ReactElement;
info?: AccountMenuInfo;
children?: React.ReactNode;
};

export const VuiAccountMenu = ({ button, info, children }: Props) => {
const [isOpen, setIsOpen] = useState(false);

export const VuiAccountMenu = ({ isOpen, setIsOpen, button, info, children }: Props) => {
return (
<VuiPopover
isOpen={isOpen}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/button/buttonTertiary.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@use "sass:map";

.vuiButtonTertiary {
padding-left: $sizeXs;
padding-right: $sizeXs;

&:hover {
text-decoration: underline;
}
Expand Down
8 changes: 7 additions & 1 deletion src/lib/components/flex/FlexItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ import classNames from "classnames";
import { ReactNode } from "react";

const GROW = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as const;
const SHRINK = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as const;

type Props = {
children?: ReactNode;
grow?: (typeof GROW)[number] | boolean;
shrink?: (typeof SHRINK)[number] | boolean;
className?: string;
truncate?: boolean;
};

export const VuiFlexItem = ({ children, grow, className, truncate, ...rest }: Props) => {
export const VuiFlexItem = ({ children, grow, shrink, className, truncate, ...rest }: Props) => {
const isGrowNone = grow === false;
const isShrinkNone = shrink === false;

const classes = classNames(
"vuiFlexItem",
{
[`vuiFlexItem--flexGrow${grow}`]: typeof grow === "number",
"vuiFlexItem--flexGrowNone": isGrowNone,
[`vuiFlexItem--flexShrink${shrink}`]: typeof shrink === "number",
"vuiFlexItem--flexShrinkNone": isShrinkNone,
"vuiFlexItem--truncate": truncate
},
className
Expand Down
15 changes: 13 additions & 2 deletions src/lib/components/flex/_flexItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
flex-basis: 0%;
}

.vuiFlexItem--truncate {
min-width: 40px;
}

@for $i from 0 through 10 {
.vuiFlexItem--flexGrow#{$i} {
flex-grow: $i;
Expand All @@ -15,6 +19,13 @@
flex-grow: 0;
}

.vuiFlexItem--truncate {
min-width: 40px;
@for $i from 0 through 10 {
.vuiFlexItem--flexShrink#{$i} {
flex-shrink: $i;
}
}

.vuiFlexItem--flexShrinkNone {
flex-basis: auto;
flex-shrink: 0;
}
3 changes: 2 additions & 1 deletion src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { VuiMenuItem } from "./menu/MenuItem";
import { VuiModal } from "./modal/Modal";
import { VuiOptionsList } from "./optionsList/OptionsList";
import { VuiOptionsListItem } from "./optionsList/OptionsListItem";
import { OptionListItem } from "./optionsList/types";
import { VuiPopover } from "./popover/Popover";
import { VuiPortal } from "./portal/Portal";
import { VuiPrompt } from "./prompt/Prompt";
Expand All @@ -49,7 +50,7 @@ import { TEXT_COLOR, TITLE_SIZE } from "./typography/types";
import { VuiTitle } from "./typography/Title";
import { VuiToggle } from "./toggle/Toggle";

export type { AppContentPadding, ButtonColor, CalloutColor, TabSize };
export type { AppContentPadding, ButtonColor, CalloutColor, OptionListItem, TabSize };

export {
BADGE_COLOR,
Expand Down
25 changes: 8 additions & 17 deletions src/lib/components/optionsList/OptionsList.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import classNames from "classnames";
import { VuiText } from "../typography/Text";
import { VuiTextColor } from "../typography/TextColor";
import { TextColor } from "../typography/types";
import { VuiOptionsListItem } from "./OptionsListItem";
import { OptionListItem } from "./types";

type Props = {
options: {
value: string;
label: string;
color?: TextColor;
}[];
options: OptionListItem[];
onSelectOption: (value: string) => void;
selectedOption?: string;
isSelectable?: boolean;
Expand All @@ -30,20 +24,17 @@ export const VuiOptionsList = ({

return (
<div className={classes} {...rest}>
{options.map(({ value, label, color = "normal" }) => (
{options.map(({ value, label, href, onClick, color }) => (
<VuiOptionsListItem
key={value}
value={value}
onClick={onSelectOption}
label={label}
color={color}
href={href}
onClick={onClick ?? onSelectOption}
isSelectable={isSelectable}
isSelected={value === selectedOption}
>
<VuiText>
<VuiTextColor color={color}>
<p>{label}</p>
</VuiTextColor>
</VuiText>
</VuiOptionsListItem>
/>
))}
</div>
);
Expand Down
63 changes: 45 additions & 18 deletions src/lib/components/optionsList/OptionsListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
import React from "react";
import { Link } from "react-router-dom";
import { BiCheck } from "react-icons/bi";
import { VuiFlexContainer } from "../flex/FlexContainer";
import { VuiFlexItem } from "../flex/FlexItem";
import { VuiIcon } from "../icon/Icon";
import { BiCheck } from "react-icons/bi";
import { VuiText } from "../typography/Text";
import { VuiTextColor } from "../typography/TextColor";
import { OptionListItem } from "./types";

type Props = {
value: string;
children: React.ReactNode;
type Props = OptionListItem & {
isSelectable?: boolean;
isSelected?: boolean;
onClick: (value: string) => void;
};

export const VuiOptionsListItem = ({ value, children, isSelectable, isSelected, onClick, ...rest }: Props) => {
return (
<button className="vuiOptionsListItem" onClick={() => onClick(value)} {...rest}>
<VuiFlexContainer alignItems="center" spacing="xs">
{isSelectable && (
<VuiFlexItem grow={false}>
<VuiIcon className={isSelected ? "" : "vuiOptionsListItem__selected--unselected"} color="accent" size="s">
<BiCheck />
</VuiIcon>
</VuiFlexItem>
)}
export const VuiOptionsListItem = ({
value,
label,
color = "normal",
href,
onClick,
isSelectable,
isSelected,
...rest
}: Props) => {
const content = (
<VuiFlexContainer alignItems="center" spacing="xs">
{isSelectable && (
<VuiFlexItem grow={false}>
<VuiIcon className={isSelected ? "" : "vuiOptionsListItem__selected--unselected"} color="accent" size="s">
<BiCheck />
</VuiIcon>
</VuiFlexItem>
)}
<VuiFlexItem grow={false}>
<VuiText>
<VuiTextColor color={color}>
<p>{label}</p>
</VuiTextColor>
</VuiText>
</VuiFlexItem>
</VuiFlexContainer>
);

if (href) {
return (
<Link className="vuiOptionsListItem" to={href} onClick={() => onClick?.(value)} {...rest}>
{content}
</Link>
);
}

<VuiFlexItem grow={false}>{children}</VuiFlexItem>
</VuiFlexContainer>
return (
<button className="vuiOptionsListItem" onClick={() => onClick?.(value)} {...rest}>
{content}
</button>
);
};
9 changes: 9 additions & 0 deletions src/lib/components/optionsList/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { TextColor } from "../typography/types";

export type OptionListItem = {
value: string;
label: string;
href?: string;
onClick?: (value: string) => void;
color?: TextColor;
};