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

Dropdown Component + some general adjustments #21

Merged
merged 9 commits into from
Dec 18, 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
7 changes: 0 additions & 7 deletions babel.config.js

This file was deleted.

232 changes: 114 additions & 118 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
"author": "Code0",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"@babel/preset-react": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@mdx-js/react": "^2.1.2",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-typescript": "^8.3.0",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-typescript": "^8.5.0",
"@storybook/addon-a11y": "^7.6.4",
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-interactions": "^7.5.3",
Expand All @@ -48,7 +44,9 @@
"rimraf": "^5.0.5",
"rollup": "^2.60.0",
"rollup-plugin-dts": "^4.0.1",
"rollup-plugin-postcss": "^4.0.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.43.5",
"sass-loader": "^12.3.0",
"storybook": "^7.5.3",
Expand All @@ -67,5 +65,8 @@
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"rollup-plugin-visualizer": "^5.11.0"
Copy link
Member

Choose a reason for hiding this comment

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

Is this intended to be a dependency instead of a dev devependency? Based on the name, I would expect it as dev dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's a mistake. Will be changed in a future MR.

}
}
70 changes: 43 additions & 27 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import dts from "rollup-plugin-dts";

import postcss from "rollup-plugin-postcss";
import visualizer from 'rollup-plugin-visualizer';
import dts from "rollup-plugin-dts";
import {getFiles} from "./scripts/buildUtils";

const packageJson = require("./package.json");
const extensions = ['.js', '.ts', '.jsx', '.tsx'];
const excludeExtensions = [
'test.js',
'test.ts',
'test.jsx',
'test.tsx',
'stories.js',
'stories.ts',
'stories.jsx',
'stories.tsx',
];

export default [
{
export default [{
input: "src/index.ts",
output: [
{
file: packageJson.main,
format: "cjs",
sourcemap: false,
},
{
file: packageJson.module,
format: "esm",
sourcemap: false,
},
{
file: packageJson.main,
format: "cjs",
sourcemap: false,
},
{
file: packageJson.module,
format: "esm",
sourcemap: false,
},
],
plugins: [
resolve(),
commonjs(),
/* for @rollup/plugin-typescript */
typescript({
tsconfig: "./tsconfig.json",
exclude: ["**/__stories__", "**/*.stories.tsx"]
}),
postcss(),
resolve(),
commonjs(),
typescript({
tsconfig: "./tsconfig.json",
declaration: true,
declarationDir: 'dist',
exclude: ["**/__stories__", "**/*.stories.tsx"]
}),
postcss(),
visualizer({
filename: 'bundle-analysis.html',
open: false,
}),
],
external: ["react", "react-dom"],
},
{
}, {
input: "dist/esm/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "esm" }],
output: [{file: "dist/index.d.ts", format: "esm"}],
plugins: [dts()],
external: [/\.(css|less|scss)$/],
},
];
}]
35 changes: 26 additions & 9 deletions src/components/button-group/ButtonGroup.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,38 @@

border: none;
width: fit-content;
margin-bottom: 1rem;
position: relative;
margin-bottom: 1rem !important;
display: flex;
flex-flow: row wrap;

> * {
* {
margin-bottom: 0;
}

.button {
margin-bottom: 0;
border-radius: 0;
display: flex;
}

> div, .dropdown__trigger, .dropdown {
display: flex;
margin-bottom: 0 !important;
border-radius: 0 !important;
}

&:first-child {
border-bottom-left-radius: .5rem !important;
border-top-left-radius: .5rem !important;
&__first {
.button {
border-top-left-radius: $borderRadius !important;
border-bottom-left-radius: $borderRadius !important;
}
}

&:last-child {
border-bottom-right-radius: .5rem !important;
border-top-right-radius: .5rem !important;
&__last {
.button {
border-top-right-radius: $borderRadius !important;
border-bottom-right-radius: $borderRadius !important;
}
}

}
8 changes: 7 additions & 1 deletion src/components/button-group/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ const ButtonGroup: React.FC<ButtonGroupType> = (props) => {
const {children} = props

return <div className={"button-group"}>
{children}

{children.map((child, i) => {
return <div
className={`${i == 0 || i == children.length - 1 ? i == 0 ? "button-group__first" : "button-group__last" : "button-group__item"}`}>
{child}
</div>
})}
</div>
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {
DetailedHTMLProps,
ReactNode
} from "react";
import {getChild, getContent} from "../utils";
import {getChild, getContent} from "../../utils/utils";

export interface ButtonType extends DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement> {
children: ReactNode | ReactNode[]
Expand Down
74 changes: 74 additions & 0 deletions src/components/dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {Meta} from "@storybook/react";
import React from "react";
import Dropdown from "./Dropdown";
import Button from "../button/Button";
import {IconAbc, IconMail, IconSearch} from "@tabler/icons-react";
import ButtonGroup from "../button-group/ButtonGroup";
import Input from "../input/Input";

const meta: Meta = {
title: "Dropdown",
component: Dropdown
}

export default meta;

export const Dropdowns = () => {
return <>
<Dropdown position={"bottom"} align={"start"}>
<Dropdown.Trigger>
<Button>Open Dropdown</Button>
</Dropdown.Trigger>
<Dropdown.Menu>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
</Dropdown.Menu>
</Dropdown>


<Dropdown position={"bottom"} align={"start"}>
<Dropdown.Trigger>
<Button>Open Dropdown</Button>
</Dropdown.Trigger>
<Dropdown.Menu>
<Dropdown.Header>
<Input.Control placeholder={"search..."}>
<Input.Control.Icon><IconSearch/></Input.Control.Icon>
</Input.Control>
</Dropdown.Header>
<Dropdown.Group>
<Dropdown.Group.Item>
Item 1
</Dropdown.Group.Item>
<Dropdown.Group.Item>
Item 2
</Dropdown.Group.Item>
</Dropdown.Group>
<Dropdown.Footer>
That's the footer
</Dropdown.Footer>
</Dropdown.Menu>
</Dropdown>

<ButtonGroup>
{
["secondary", "secondary", "secondary", "secondary"].map((value, index) => {
// @ts-ignore
return (index % 2 == 0) ? <Button disabled={(index % 2) == 0} variant={value}>
{(index % 2) == 0 ? <Button.Icon><IconAbc/></Button.Icon> : null}
{value}
</Button> : <Dropdown position={"bottom"} align={"start"}>
<Dropdown.Trigger>
<Button disabled={(index % 2) == 0} variant={"secondary"}>
{(index % 2) == 0 ? <Button.Icon><IconAbc/></Button.Icon> : null}
{value}
</Button>
</Dropdown.Trigger>
<Dropdown.Menu>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
</Dropdown.Menu>
</Dropdown>
})
}
</ButtonGroup>
</>
}
Loading