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

Feat: Implement custom button #7

Merged
merged 1 commit into from
Nov 8, 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
10 changes: 9 additions & 1 deletion src/app/elements/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { CustomButton } from '@/components/Buttons/CustomButton';
import { Chart } from '@/components/Charts/Chart';
import container from '@/container';
import CountryRepository from '@/domain/repositories/CountryRepository';

/**
* You can use this page to try and show off your components.
* It's not accessible from the UI, but you can reach it by manually navigating to /elements
*/
export default async function Elements() {
const countryData = await container.resolve<CountryRepository>('CountryRepository').getCountryData(50);
return <Chart chartData={countryData.fcsGraph} />;
return (
<div>
<Chart chartData={countryData.fcsGraph} />;<CustomButton variant="solid">Test</CustomButton>
<CustomButton variant="bordered">Test</CustomButton>
<CustomButton variant="flat">Test</CustomButton>
</div>
);
}
28 changes: 28 additions & 0 deletions src/components/Buttons/CustomButton.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file contains a lot of duplicated code. Generally all cases could be summarized in one and there is no need of having the same component with few changes for all cases. Imagine having 100 variants for the button, this simply will not work and the file will grow a lot. It's considered a good practice to separate the concerns (here styling and react component).

Nevertheless we use tailwindcss, which means we do not use style on the component but everything will be with className="tailwindClasses". Also you do not need to check for the theme here, neither you do need the useEffects for the theme switch. Everything you need will be handled by NextUI and TailwindCSS. Colors and everything will be defined in thiw way, not custom css colors: Check here. Also check the existing tailwind.config.js and research how to apply all colors and customize them there.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Button } from '@nextui-org/button';
import clsx from 'clsx';

import { CustomButtonProps } from '@/domain/props/CustomButtonProps';

/**
* Custom button component in the variants solid, bordered and flat. It can be used like a normal NextUI button
* component.
* @param variant solid | bordered | flat
*/

export function CustomButton({ children, ...attributes }: CustomButtonProps) {
const { variant } = attributes;

return (
<Button
{...attributes}
className={clsx({
'hover:bg-outlinedHover': variant === 'bordered',
'hover:bg-hover dark:text-foreground': variant === 'flat' || variant === 'solid',
'bg-clickableSecondary hover:text-background ': variant === 'flat',
'bg-primary dark:hover:bg-hover text-background': variant === 'solid',
})}
>
{children}
</Button>
);
}
5 changes: 5 additions & 0 deletions src/domain/props/CustomButtonProps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ButtonProps } from '@nextui-org/button';

export interface CustomButtonProps extends ButtonProps {
children: React.ReactNode;
}
6 changes: 6 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module.exports = {
background: '#F5F5F5',
divider: '#157DBC',
focus: '#157DBC',
hover: '#005489',
outlinedHover: '#E3F2FD',
clickableSecondary: '#E6E6E6',
danger: '#D32F2F',
warning: '#FFB600',
clusterGreen: '#85E77C',
Expand All @@ -47,6 +50,9 @@ module.exports = {
background: '#121212',
divider: '#157DBC',
focus: '#157DBC',
hover: '#0F6396',
outlinedHover: '#0F6396',
clickableSecondary: '#424242',
danger: '#EF5350',
warning: '#FFEB3B',
clusterGreen: '#A3F39C',
Expand Down