generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Added Tailwind Button Components #641
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
Merged
bzzz-coding
merged 3 commits into
hackforla:develop
from
bzzz-coding:tailwind-migration
Feb 25, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import React from "react"; | ||
| import clsx from "clsx"; | ||
| import Typography from "tw-components/Typography"; | ||
|
|
||
| const buttonSizes = { | ||
| small: "px-[24px] h-[32px]", | ||
| "small-long": "px-[40px] h-[32px]", | ||
| medium: "px-[32px] h-[42px]", | ||
| "medium-long": "px-[48px] h-[42px]", | ||
| large: "px-[40px] h-[51px]", | ||
| "large-long": "px-[56px] h-[51px]", | ||
| "icon-only": "px-[24px] h-[42px]", | ||
| }; | ||
|
|
||
| type ButtonSize = keyof typeof buttonSizes; | ||
|
|
||
| type BaseButtonProps = { | ||
| size?: ButtonSize; | ||
| disabled?: boolean; | ||
| className?: string; | ||
| children?: React.ReactNode; | ||
| onClick?: () => void; | ||
| }; | ||
|
|
||
| // Shared styles | ||
| const baseButtonStyles = | ||
| "transition-all duration-200 flex items-center justify-center rounded-[64px] bg-blue-dark text-white hover:bg-blue-dark-hover focus:bg-blue-dark-focused focus:outline-none active:bg-blue-dark-focused disabled:bg-grey disabled:text-white disabled:cursor-not-allowed"; | ||
|
|
||
| // Dark mode styles for enabled buttons | ||
| const enabledDarkModeStyles = | ||
| "dark:bg-white dark:text-blue-dark dark:hover:bg-grey-light dark:focus:bg-[#D9DBDF] dark:active:bg-[#D9DBDF] dark:disabled:bg-grey dark:disabled:text-grey-light"; | ||
|
|
||
| // Base Button, no text, just styling | ||
| const BaseButton: React.FC<BaseButtonProps> = ({ | ||
| size = "medium", | ||
| disabled = false, | ||
| className, | ||
| children, | ||
| onClick, | ||
| }) => { | ||
| return ( | ||
| <button | ||
| className={clsx( | ||
| baseButtonStyles, | ||
| buttonSizes[size], | ||
| !disabled && enabledDarkModeStyles, | ||
| className, | ||
| )} | ||
| disabled={disabled} | ||
| onClick={onClick} | ||
| > | ||
| {children} | ||
| </button> | ||
| ); | ||
| }; | ||
|
|
||
| // Default Button, extends base button, adds typography | ||
| const buttonTypography: Record< | ||
| Exclude<ButtonSize, "icon-only">, | ||
| React.ElementType | ||
| > = { | ||
| small: Typography.Title7, | ||
| "small-long": Typography.Title7, | ||
| medium: Typography.Title6, | ||
| "medium-long": Typography.Title6, | ||
| large: Typography.Title5, | ||
| "large-long": Typography.Title5, | ||
| }; | ||
|
|
||
| type ButtonProps = Omit<BaseButtonProps, "children"> & { | ||
| size?: Exclude<ButtonSize, "icon-only">; | ||
| children: React.ReactNode; | ||
| }; | ||
|
|
||
| const Button: React.FC<ButtonProps> = ({ | ||
| size = "medium", | ||
| children, | ||
| ...props | ||
| }) => { | ||
| const TextComponent = buttonTypography[size]; | ||
| return ( | ||
| <BaseButton {...props} size={size}> | ||
| <TextComponent>{children}</TextComponent> | ||
| </BaseButton> | ||
| ); | ||
| }; | ||
|
|
||
| // Icon Button, extends base button, adds static svg | ||
| type IconButtonProps = Omit<BaseButtonProps, "size" | "children">; | ||
|
|
||
| const IconButton: React.FC<IconButtonProps> = (props) => { | ||
| return ( | ||
| <BaseButton {...props} size="icon-only" className="rounded-[24px]"> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="24" | ||
| height="24" | ||
| viewBox="0 0 24 24" | ||
| > | ||
| <path | ||
| fill="none" | ||
| stroke="currentColor" | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth="2" | ||
| d="m20 20l-4.05-4.05m0 0a7 7 0 1 0-9.9-9.9a7 7 0 0 0 9.9 9.9" | ||
| /> | ||
| </svg> | ||
| </BaseButton> | ||
| ); | ||
| }; | ||
|
|
||
| export { Button, IconButton }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.