Skip to content

Commit

Permalink
Merge pull request #3 from RealWagmi/refactor-10-11-23
Browse files Browse the repository at this point in the history
Refactor 10 11 23
  • Loading branch information
0xfantaholic authored Nov 13, 2023
2 parents f1f40f8 + 2da0d5d commit cfdce1b
Show file tree
Hide file tree
Showing 132 changed files with 1,750 additions and 3,451 deletions.
7 changes: 6 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { StorybookConfig } from "@storybook/react-vite";
const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
addons: ["@storybook/addon-links", "@storybook/addon-essentials", "@storybook/addon-interactions"],
addons: [
"@storybook/addon-links",
{ name: "@storybook/addon-essentials", options: { backgrounds: false } },
"@storybook/addon-interactions",
"@storybook/addon-themes",
],
framework: {
name: "@storybook/react-vite",
options: {},
Expand Down
24 changes: 24 additions & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- .storybook/preview-head.html -->

<!-- Pull in static files served from your Static directory or the internet -->
<!-- Example: `main.js|ts` is configured with staticDirs: ['../public'] and your font is located in the `fonts` directory inside your `public` directory -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Lexend+Deca:wght@100;200;300;400;500;600;700;800;900&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet"
/>

<style>
* {
font-family: Lexend Deca, sans-serif;
}
</style>
<!-- Or you can load custom head-tag JavaScript: -->

<!--<script src="https://use.typekit.net/xxxyyy.js"></script>-->
<!--<script>-->
<!-- try {-->
<!-- Typekit.load();-->
<!-- } catch (e) {}-->
<!--</script>-->
29 changes: 16 additions & 13 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import type { Preview } from "@storybook/react";
import type { DecoratorFn, Preview } from "@storybook/react";

import { ThemeProvider } from "styled-components";
import { dark } from "../src/theme";
import { dark, light } from "../src/theme";
import { withThemeFromJSXProvider } from "@storybook/addon-themes";

const CustomProvider = (props) => {
window.document.body.style.background = props.theme.background;
return <ThemeProvider theme={props.theme}>{props.children}</ThemeProvider>;
};

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
decorators: [
(Story) => (
<ThemeProvider theme={dark}>
<Story />
</ThemeProvider>
),
withThemeFromJSXProvider({
themes: {
dark,
light,
},
defaultTheme: "dark",
Provider: CustomProvider,
}) as DecoratorFn,
],
};

Expand Down
33 changes: 19 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,43 @@
"@storybook/react": "^7.0.12",
"@storybook/react-vite": "^7.0.12",
"@storybook/testing-library": "^0.0.14-next.2",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^12.1.3",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/react-router-dom": "^5.1.7",
"@types/rebass": "^4.0.7",
"@types/styled-components": "^5.1.25",
"prop-types": "^15.8.1",
"react-dom": "^18.2.0",
"storybook": "^7.0.12",
"typescript": "^5.0.4",
"vite": "^4.3.8",
"vitest": "^0.27.2",
"@testing-library/react": "^12.1.3",
"@vanilla-extract/vite-plugin": "^3.8.0",
"@vitejs/plugin-react": "4.0.0",
"@testing-library/jest-dom": "^5.11.6",
"jest-environment-jsdom": "^29.3.1",
"jest-styled-components": "^7.0.8",
"@types/react-router-dom": "^5.1.7",
"polished": "^3.3.2",
"prop-types": "^15.8.1",
"react-dom": "^18.2.0",
"react-router-dom": "^5.2.0",
"storybook": "^7.0.12",
"themeprovider-storybook": "^1.7.2",
"polished": "^3.3.2",
"@types/rebass": "^4.0.7"
"typescript": "^5.2.2",
"vite": "^4.3.8",
"vitest": "^0.27.2"
},
"dependencies": {
"@popperjs/core": "^2.11.8",
"@reach/portal": "^0.18.0",
"@real-wagmi/sdk": "^1.1.6",
"@storybook/addon-themes": "^7.5.3",
"@types/node": "^13.13.5",
"@types/styled-system": "^5.1.15",
"framer-motion": "10.11.2",
"react": "^18.2.0",
"react-feather": "^2.0.8",
"react-popper": "^2.3.0",
"rebass": "^4.0.7",
"styled-components": "^5.3.5",
"styled-system": "^5.1.5",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"rebass": "^4.0.7",
"react-feather": "^2.0.8"
"tslint-config-prettier": "^1.18.0"
},
"repository": "https://github.com/RealWagmi/uikit.git",
"files": [
Expand Down
176 changes: 176 additions & 0 deletions src/components/AppBtn/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import React, { useEffect, useState } from "react";
import AppBtnComponent from "./index";
import { BrowserRouter } from "react-router-dom";
import { Box, Grid } from "../Box";
import Text from "../Text";
import { InfoIcon, QuestionIcon } from "../Svg";
import Tooltip from "../Tooltip";

export default {
title: "Components/Buttons",
component: AppBtnComponent,
argTypes: {},
};

export const Buttons = () => {
const [loading, setLoading] = useState(false);

useEffect(() => {
if (loading) {
setTimeout(() => {
setLoading(false);
}, 1500);
}
}, [loading]);

return (
<BrowserRouter>
<Text variant={"h5"} m="10px 0 20px">
Default
</Text>
<Grid gridTemplateColumns="repeat(3, 1fr)" gridGap="20px">
<Text>Primary</Text>
<Text>Outlined</Text>
<Text>Text</Text>
<Box>
<AppBtnComponent>Button</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent variant={"outlined"}>Button</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent variant={"text"}>Button</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent disabled={true}>Button</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent variant={"outlined"} disabled={true}>
Button
</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent variant={"text"} disabled={true}>
Button
</AppBtnComponent>
</Box>
</Grid>
<Text variant={"h5"} m="40px 0 20px">
Small
</Text>
<Grid gridTemplateColumns="repeat(3, 1fr)" gridGap="20px">
<Text>Primary</Text>
<Text>Outlined</Text>
<Text>Text</Text>
<Box>
<AppBtnComponent scale={"small"}>Button</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent scale={"small"} variant={"outlined"}>
Button
</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent scale={"small"} variant={"text"}>
Button
</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent scale={"small"} disabled={true}>
Button
</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent scale={"small"} variant={"outlined"} disabled={true}>
Button
</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent scale={"small"} variant={"text"} disabled={true}>
Button
</AppBtnComponent>
</Box>
</Grid>
<Text variant={"h5"} m="40px 0 20px">
Error Button
</Text>
<Grid gridTemplateColumns="repeat(3, 1fr)" gridGap="20px">
<Box>
<AppBtnComponent color={"error"}>Button</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent color={"error"} variant={"outlined"}>
Button
</AppBtnComponent>
</Box>
<Box>
<AppBtnComponent color={"error"} variant={"text"}>
Button
</AppBtnComponent>
</Box>
</Grid>
<Text variant={"h5"} m="40px 0 20px">
Link Button
</Text>
<Box>
<AppBtnComponent to={"https://docs.popsicle.finance/"} target={"_blank"} width={"50%"}>
Button
</AppBtnComponent>
</Box>
<Text variant={"h5"} m="40px 0 20px">
With Start/End components
</Text>
<Grid gridTemplateColumns="repeat(3, 1fr)" gridGap="20px">
<AppBtnComponent startIcon={<InfoIcon size={"16px"} />}>Button</AppBtnComponent>
<AppBtnComponent endIcon={<QuestionIcon size={"16px"} />} variant={"outlined"}>
Button
</AppBtnComponent>
<AppBtnComponent
color={"error"}
disabled={true}
variant={"text"}
startIcon={
<Tooltip content={"Simple text"}>
<InfoIcon size={"16px"} />
</Tooltip>
}
endIcon={
<Tooltip
content={
<>
Simple Text
<br />
Simple Text
<br />
Simple Text
<br />
Simple Text
<br />
</>
}
>
<QuestionIcon size={"16px"} />
</Tooltip>
}
>
With Tooltips
</AppBtnComponent>
</Grid>

<Text variant={"h5"} m="40px 0 20px">
With Loader
</Text>

<AppBtnComponent
width={"50%"}
onClick={() => {
setLoading(true);
}}
loading={loading}
variant={"outlined"}
>
Click here
</AppBtnComponent>
</BrowserRouter>
);
};
73 changes: 73 additions & 0 deletions src/components/AppBtn/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import styled from "styled-components";
import { variant } from "styled-system";
import { variantVariants, scaleVariants } from "./theme";
import { AppBtnProps } from "./types";
import LoadingSpinner from "../Loaders/LoadingSpinner";

const AppBtnWrap = styled.button<AppBtnProps>`
${({ theme, color }) =>
variant({
prop: "variant",
variants: variantVariants(theme, color),
})}
${variant({
prop: "scale",
variants: scaleVariants,
})}
position: relative;
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
border: none;
cursor: pointer;
text-decoration: none;
width: ${({ width }) => width || "100%"};
&:disabled {
cursor: default;
opacity: 0.5;
}
`;

const AppBtnContainer = styled.span<{ isLoading?: boolean }>`
display: flex;
align-items: center;
justify-content: center;
opacity: ${({ isLoading }) => (isLoading ? 0.3 : 1)};
transition: opacity 0.15s;
`;
const AppBtnLoader = styled.span<{ isLoading?: boolean }>`
position: absolute;
display: flex;
opacity: ${({ isLoading }) => (isLoading ? 1 : 0)};
pointer-events: none;
transition: opacity 0.15s;
`;

const AppBtnContent = styled.span`
margin: 0 8px;
`;

AppBtnWrap.defaultProps = {
variant: "default",
scale: "default",
color: "primary",
as: "button",
};

export default function AppBtn({ loading, ...props }: AppBtnProps & { loading?: boolean }) {
return (
<AppBtnWrap {...props} as={props.to ? "a" : "button"} href={props.to}>
<AppBtnContainer isLoading={loading}>
{props.startIcon}
<AppBtnContent>{props.children}</AppBtnContent>
{props.endIcon}
</AppBtnContainer>
<AppBtnLoader isLoading={loading}>
<LoadingSpinner duration={"0.4s"} />
</AppBtnLoader>
</AppBtnWrap>
);
}
Loading

0 comments on commit cfdce1b

Please sign in to comment.