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

Base Components #16

Merged
merged 14 commits into from
Oct 4, 2024
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
111 changes: 59 additions & 52 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,52 +1,59 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": [
"airbnb",
"airbnb/hooks",
"airbnb-typescript",
"@feature-sliced",
"plugin:storybook/recommended"
],
"ignorePatterns": ["*.pnp.*", "*.config.ts", "node_modules", ".yarn", ".eslintrc.cjs", "dist/**", "**/*.stories.tsx"],
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.app.json"
},
"plugins": [
"@typescript-eslint",
"react"
],
"rules": {
"react/react-in-jsx-scope": 'off',
"react/require-default-props": "off",
'import/extensions': [
'error',
'ignorePackages',
{
'': 'never',
'js': 'never',
'jsx': 'never',
'ts': 'never',
'tsx': 'never'
}
],
}
}
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": [
"airbnb",
"airbnb/hooks",
"airbnb-typescript",
"plugin:storybook/recommended"
],
"ignorePatterns": ["*.pnp.*", "*.config.ts", "node_modules", ".yarn", ".eslintrc.cjs", "dist/**", "**/*.stories.tsx"],
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.app.json"
},
"plugins": [
"@typescript-eslint",
"react"
],
"rules": {
"react/react-in-jsx-scope": 'off',
'import/extensions': [
'error',
'ignorePackages',
{
'': 'never',
'js': 'never',
'jsx': 'never',
'ts': 'never',
'tsx': 'never'
}
],
'react/require-default-props': 'off',
'react/no-unknown-property': [
'error',
{
ignore: ['css'],
}
],
'react/jsx-props-no-spreading': 'off',
'@typescript-eslint/no-use-before-define': 'off'
},
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dist-ssr
*.sln
*.sw?

*storybook.log
*storybook.log
21 changes: 15 additions & 6 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import type { StorybookConfig } from "@storybook/react-vite";

import { join, dirname } from "path";

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, "package.json")));
}
const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
getAbsolutePath("@storybook/addon-onboarding"),
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@chromatic-com/storybook"),
getAbsolutePath("@storybook/addon-interactions"),
],
framework: {
name: "@storybook/react-vite",
name: getAbsolutePath("@storybook/react-vite"),
options: {},
},
};
Expand Down
8 changes: 8 additions & 0 deletions .storybook/preview.ts → .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Preview } from "@storybook/react";
import PassportProvider from '../src/providers/PassportProvider';

const preview: Preview = {
parameters: {
Expand All @@ -9,6 +10,13 @@ const preview: Preview = {
},
},
},
decorators: [
(Story) => (
<PassportProvider>
<Story />
</PassportProvider>
)
],
};

export default preview;
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,30 @@
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@tanstack/react-query": "^5.59.0",
"emotion-normalize": "^11.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"react-router-dom": "^6.26.2"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.9.0",
"@chromatic-com/storybook": "1.9.0",
"@emotion/babel-plugin": "^11.12.0",
"@eslint/js": "^9.9.0",
"@feature-sliced/eslint-config": "^0.1.1",
"@storybook/addon-essentials": "^8.3.4",
"@storybook/addon-interactions": "^8.3.4",
"@storybook/addon-links": "^8.3.4",
"@storybook/addon-onboarding": "^8.3.4",
"@storybook/blocks": "^8.3.4",
"@storybook/react": "^8.3.4",
"@storybook/react-vite": "^8.3.4",
"@storybook/test": "^8.3.4",
"@storybook/addon-essentials": "8.3.4",
"@storybook/addon-interactions": "8.3.4",
"@storybook/addon-links": "8.3.4",
"@storybook/addon-onboarding": "8.3.4",
"@storybook/blocks": "8.3.4",
"@storybook/react": "8.3.4",
"@storybook/react-vite": "8.3.4",
"@storybook/test": "8.3.4",
"@types/eslint-plugin-jsx-a11y": "^6",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/eslint-plugin": "7.0.0",
"@typescript-eslint/parser": "^8.6.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "8.57.0",
"eslint-config-airbnb": "^19.0.4",
Expand All @@ -52,10 +54,11 @@
"eslint-plugin-react-refresh": "^0.4.9",
"eslint-plugin-storybook": "^0.9.0",
"globals": "^15.9.0",
"storybook": "^8.3.4",
"storybook": "8.3.4",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^2.1.1"
},
Expand Down
5 changes: 5 additions & 0 deletions src/assets/icons/default-avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/eye-off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/eye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/assets/icons/tag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/icons/x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/components/avatar/avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Meta, StoryObj } from '@storybook/react';
import Avatar from '@components/avatar';

const meta: Meta<typeof Avatar> = {
title: 'Components/Avatar',
component: Avatar,
argTypes: {
css: { control: 'object' },
},
};

export default meta;

type Story = StoryObj<typeof Avatar>;

export const AvatarImage: Story = {
args: {
src: 'https://picsum.photos/200',
},
};

export const DefaultAvatar: Story = {
args: {
},
};
21 changes: 21 additions & 0 deletions src/components/avatar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ImgHTMLAttributes } from 'react';
import useAvatarStyle from '@components/avatar/useAvatarStyle';
import { CSSObject } from '@emotion/react';
import defaultAvatar from '@assets/icons/default-avatar.svg';

interface AvatarProps extends ImgHTMLAttributes<HTMLImageElement> {
src?: string;
alt?: string;
css?: CSSObject;
}

function Avatar({
src, alt, css, ...rest
}: AvatarProps) {
const { avatarStyle } = useAvatarStyle();
return (
<img src={src || defaultAvatar} css={[avatarStyle, css]} alt={alt || 'avatar'} {...rest} />
);
}

export default Avatar;
16 changes: 16 additions & 0 deletions src/components/avatar/useAvatarStyle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import useTheme from '@hooks/useTheme';
import { css } from '@emotion/react';

function useAvatarStyle() {
const theme = useTheme();

const avatarStyle = css`
border-radius: ${theme.corners.round};
width: 60px;
height: 60px;
`;

return { avatarStyle };
}

export default useAvatarStyle;
53 changes: 53 additions & 0 deletions src/components/button/button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Meta, StoryObj } from '@storybook/react';
import Button from '@components/button';
import icon from '@assets/icons/eye.svg';

const meta: Meta<typeof Button> = {
title: 'Components/Button',
component: Button,
argTypes: {

buttonTheme: {
control: 'radio',
options: ['default', 'dark', 'light-outlined'],
},
children: {
control: 'text',
defaultValue: 'Button Text',
},
css: { control: 'object' },
},
};

export default meta;

type Story = StoryObj<typeof Button>;

export const Default: Story = {
args: {
buttonTheme: 'default',
children: 'Default Button',
},
};

export const WithIcon: Story = {
args: {
buttonTheme: 'dark',
children: 'Dark Button',
icon,
},
};

export const CustomStyled: Story = {
args: {
buttonTheme: 'default',
children: 'Custom Styled Button',
css: {
backgroundColor: 'lightblue',
padding: '10px 20px',
borderRadius: '5px',
border: 'none',
cursor: 'pointer',
},
},
};
Loading