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

Rewrite select #137

Merged
merged 32 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
dfc2df1
Add select changes
vineethasok Sep 11, 2023
6b6c563
Add Select Changes
vineethasok Sep 12, 2023
db87641
Remove drag feature
vineethasok Sep 12, 2023
da1ed82
Fix Select changes
vineethasok Sep 14, 2023
4869b20
Fix tests
vineethasok Sep 14, 2023
96586a3
Fix sort issue
vineethasok Sep 15, 2023
012205f
Fix package install
vineethasok Sep 15, 2023
a6c5261
Remove yarn lock
vineethasok Sep 15, 2023
0f1b611
Fix initial loading of the item
vineethasok Sep 16, 2023
d091ac5
Fix showSearch in storybook
vineethasok Sep 17, 2023
f588455
Update storybook orientation
vineethasok Sep 17, 2023
2e93103
Call onSelect on value change
vineethasok Sep 17, 2023
09a855f
Add Select Changes
vineethasok Sep 20, 2023
10c917c
Fix Hidden Select Component
vineethasok Sep 20, 2023
779b5d4
Fix linting issues
vineethasok Sep 20, 2023
0ff570e
Fix show Search in Select
vineethasok Sep 20, 2023
2fa34a2
Fix Select Open State issue
vineethasok Sep 21, 2023
7aef59a
Add Select Changes
vineethasok Sep 23, 2023
1714813
Add Select changes
vineethasok Sep 23, 2023
79d47fc
Add Select Changes
vineethasok Sep 24, 2023
8ce431c
Fix Multi select sorting
vineethasok Sep 24, 2023
7d1adaa
Remove open from story book
vineethasok Sep 25, 2023
3037322
Fix initial selection and also props naming
vineethasok Sep 25, 2023
c9fd4b6
Add styling changes
vineethasok Sep 25, 2023
a0e5ec6
Change onChange to onSelect in Select and MultiSelect props
vineethasok Sep 25, 2023
f3c7286
Fix Select Test
vineethasok Sep 25, 2023
40a0950
Add types
vineethasok Sep 25, 2023
55a48a2
Fix incorrect assignment
vineethasok Sep 25, 2023
626241e
Fix Select Styling
vineethasok Sep 25, 2023
c487ce0
Merge branch 'main' into rewrite-select
vineethasok Sep 25, 2023
721b8ac
Merge branch 'main' into rewrite-select
vineethasok Sep 26, 2023
85460a1
Add Ellipsis changes
vineethasok Sep 26, 2023
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
509 changes: 70 additions & 439 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.4",
"@radix-ui/react-tooltip": "^1.0.6",
"cmdk": "^0.2.0",
"lodash": "^4.17.21",
"react-syntax-highlighter": "^15.5.0"
"react-sortablejs": "^6.1.4",
"react-syntax-highlighter": "^15.5.0",
"sortablejs": "^1.15.0"
},
"devDependencies": {
"@radix-ui/react-switch": "^1.0.2",
Expand All @@ -81,6 +82,7 @@
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/react-syntax-highlighter": "^15.5.7",
"@types/sortablejs": "^1.15.2",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
Expand Down
62 changes: 51 additions & 11 deletions src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import styled from "styled-components";
import { Icon } from "@/components";
import { HorizontalDirection, Icon, IconName } from "@/components";
import { HTMLAttributes, MouseEvent, ReactNode } from "react";
import { EllipsisContainer } from "../commonElement";
export type BadgeState =
| "default"
| "success"
Expand All @@ -11,24 +13,26 @@ export type BadgeState =

export type BadgeSize = "sm" | "md";

export interface BadgeProps {
text: string;
export interface CommonBadgeProps extends HTMLAttributes<HTMLDivElement> {
text: ReactNode;
state?: BadgeState;
size?: BadgeSize;
icon?: IconName;
iconDir?: HorizontalDirection;
}

export interface DismissibleBadge extends BadgeProps {
export interface DismissibleBadge extends CommonBadgeProps {
dismissible: true;
onClose: () => void;
onClose: (e: MouseEvent<HTMLOrSVGElement>) => void;
}

export interface NonDismissibleBadge extends BadgeProps {
export interface NonDismissibleBadge extends CommonBadgeProps {
dismissible?: never;
onClose?: never;
}

const Wrapper = styled.div<{ $state?: BadgeState; $size?: BadgeSize }>`
display: inline-block;
display: inline-flex;
${({ $state = "default", $size = "md", theme }) => `
background-color: ${theme.click.badge.color.background[$state]};
color: ${theme.click.badge.color.text[$state]};
Expand All @@ -45,29 +49,65 @@ const Content = styled.div<{ $state?: BadgeState; $size?: BadgeSize }>`
gap: ${({ $size = "md", theme }) => theme.click.badge.space[$size].gap};
`;

const CrossContainer = styled.svg<{ $state?: BadgeState; $size?: BadgeSize }>`
const SvgContainer = styled.svg<{ $state?: BadgeState; $size?: BadgeSize }>`
${({ $state = "default", $size = "md", theme }) => `
color: ${theme.click.badge.color.text[$state]};
height: ${theme.click.badge.icon[$size].size.height};
width: ${theme.click.badge.icon[$size].size.width};
`}
`;
const BadgeContent = styled(EllipsisContainer)<{
$state?: BadgeState;
$size?: BadgeSize;
}>`
svg {
${({ $state = "default", $size = "md", theme }) => `
color: ${theme.click.badge.color.text[$state]};
height: ${theme.click.badge.icon[$size].size.height};
width: ${theme.click.badge.icon[$size].size.width};
gap: inherit;
`}
}
`;

export type BadgeProps = NonDismissibleBadge | DismissibleBadge;

export const Badge = ({
icon,
iconDir,
text,
state = "default",
size,
dismissible,
onClose,
}: NonDismissibleBadge | DismissibleBadge) => (
...props
}: BadgeProps) => (
<Wrapper
$state={state}
$size={size}
{...props}
>
<Content>
{text}
{icon && iconDir === "start" && (
<SvgContainer
as={Icon}
name={icon}
$state={state}
$size={size}
/>
)}
<BadgeContent>{text}</BadgeContent>
{icon && iconDir === "end" && (
<SvgContainer
as={Icon}
name={icon}
$state={state}
$size={size}
/>
)}

{dismissible && (
<CrossContainer
<SvgContainer
name="cross"
$state={state}
as={Icon}
Expand Down
5 changes: 4 additions & 1 deletion src/components/GenericMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const GenericMenuItem = styled.div`
color:${theme.click.genericMenu.item.color.text.hover};
cursor: pointer;
}
&[data-state="open"] {
&[data-state="open"], &[data-state-"checked"] {
background:${theme.click.genericMenu.item.color.background.active};
color:${theme.click.genericMenu.item.color.text.active};
font: ${theme.click.genericMenu.item.typography.label.active};
Expand All @@ -114,4 +114,7 @@ export const GenericMenuItem = styled.div`
&[data-state="open"] .dropdown-arrow {
left: 0.5rem;
}
&[hidden] {
display: none;
}
`;
55 changes: 55 additions & 0 deletions src/components/IconWrapper/IconWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ReactNode } from "react";
import { HorizontalDirection, Icon, IconName } from "@/components";
import { IconSize } from "@/components/Icon/types";
import styled from "styled-components";
import { EllipsisContainer } from "../commonElement";

const LabelContainer = styled.span`
display: flex;
align-items: center;
justify-content: flex-start;
width: 100%;
width: -webkit-fill-available;
width: fill-available;
width: stretch;
gap: ${({ theme }) => theme.click.sidebar.navigation.item.default.space.gap};
`;

const IconWrapper = ({
icon,
iconDir = "start",
size = "sm",
width,
height,
children,
}: {
icon?: IconName;
iconDir?: HorizontalDirection;
children: ReactNode;
size?: IconSize;
width?: number | string;
height?: number | string;
}) => {
return (
<LabelContainer>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label is not aligned when there's an error

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error may happen to the input and other form elements too
Should I fix them in this PR or a new one separately for them? @serdec

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another one is ok

{icon && iconDir === "start" && (
<Icon
name={icon}
size={size}
width={width}
height={height}
/>
)}
<EllipsisContainer>{children}</EllipsisContainer>
{icon && iconDir === "end" && (
<Icon
name={icon}
size={size}
width={width}
height={height}
/>
)}
</LabelContainer>
);
};
export default IconWrapper;
137 changes: 137 additions & 0 deletions src/components/Select/MultiSelect.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { Icon } from "@/components";
import { MultiSelect, MultiSelectProps } from "./MultiSelect";
import { selectOptions } from "./selectOptions";
import { useEffect, useState } from "react";
interface Props extends Omit<MultiSelectProps, "value"> {
clickableNoData?: boolean;
value: string;
childrenType: "children" | "options";
}
const MultiSelectExample = ({
clickableNoData,
childrenType,
value,
...props
}: Props) => {
const [selectedValues, setSelectedValues] = useState(
value ? value.split(",") : undefined
);
useEffect(() => {
setSelectedValues(value ? value.split(",") : undefined);
}, [value]);

if (childrenType === "options") {
return (
<MultiSelect
value={selectedValues}
onCreateOption={
clickableNoData ? search => console.log("Clicked ", search) : undefined
}
options={selectOptions}
onChange={value => setSelectedValues(value)}
{...props}
/>
);
}
return (
<MultiSelect
value={value ? value.split(",") : undefined}
onCreateOption={
clickableNoData ? search => console.log("Clicked ", search) : undefined
}
{...props}
>
<MultiSelect.Group heading="Group label">
<MultiSelect.Item value="content0">
<Icon name="user" />
Content0
</MultiSelect.Item>
</MultiSelect.Group>
<div>
<MultiSelect.Item value="content1">Content1 long text content</MultiSelect.Item>
</div>
<MultiSelect.Item
value="content2"
label="Content2"
/>
<MultiSelect.Item value="content3">Content3</MultiSelect.Item>
</MultiSelect>
);
};
export default {
component: MultiSelectExample,
title: "Forms/MultiSelect",
tags: ["form-field", "select", "autodocs"],
argTypes: {
label: { control: "text" },
disabled: { control: "boolean" },
sortable: { control: "boolean" },
error: { control: "text" },
value: { control: "text" },
defaultValue: { control: "text" },
name: { control: "text" },
required: { control: "boolean" },
showSearch: { control: "boolean" },
form: { control: "text" },
clickableNoData: { control: "boolean" },
showCheck: { control: "boolean" },
orientation: { control: "inline-radio", options: ["horizontal", "vertical"] },
dir: { control: "inline-radio", options: ["start", "end"] },
},
};

export const Playground = {
args: {
label: "Label",
value: "content1",
showSearch: true,
childrenType: "children",
},
parameters: {
docs: {
source: {
transform: (_: string, story: { args: Props; [x: string]: unknown }) => {
const { clickableNoData, childrenType, value, ...props } = story.args;
return `<MultiSelect\n value={${JSON.stringify((value ?? "").split(","))}}\n${
clickableNoData
? " onCreateOption={search => console.log('Clicked ', search)}\n"
: ""
}
${Object.entries(props)
.flatMap(([key, value]) =>
typeof value === "boolean"
? value
? ` ${key}`
: []
: ` ${key}=${typeof value == "string" ? `"${value}"` : `{${value}}`}`
)
.join("\n")}
${childrenType === "options" ? "/" : ""}>
${
childrenType !== "options"
? `
<MultiSelect.Group heading="Group label">
<MultiSelect.Item value="content0">
<Icon name="user" />
Content0
</MultiSelect.Item>
</MultiSelect.Group>
<div>
<MultiSelect.Item value="content1">Content1 long text content</MultiSelect.Item>
</div>
<MultiSelect.Item
value="content2"
disabled
>
Content2
</MultiSelect.Item>
<MultiSelect.Item value="content3">Content3</MultiSelect.Item>
</Select>
`
: ""
}`;
},
},
},
},
};
Loading