-
Notifications
You must be signed in to change notification settings - Fork 0
KernButtons shared components #39
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
+169
−2
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
daa7128
Refactoring buttons and adding more to submodules
lumburovskalina 417daa2
Moved IconButton to submodules
lumburovskalina 8a93ceb
Icon button changes
lumburovskalina cc4c9ab
PR comments
lumburovskalina 9dd1624
Added className to the combined classes
lumburovskalina 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
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,61 @@ | ||
import { combineClassNames } from "@/submodules/javascript-functions/general"; | ||
import { useMemo } from "react"; | ||
|
||
export type ButtonAsTextProps = { | ||
text: string; | ||
color?: string; | ||
onClick?: () => void; | ||
disabled?: boolean; | ||
iconLeft?: (props: any) => React.ReactNode; | ||
iconRight?: (props: any) => React.ReactNode; | ||
iconColor?: string; | ||
size?: 'small' | 'medium' | 'large'; | ||
className?: string; | ||
} | ||
|
||
export default function ButtonAsText(props: ButtonAsTextProps) { | ||
const classCombined = useMemo(() => combineClassNames( | ||
'disabled:text-gray-400 disabled:cursor-not-allowed flex items-center space-x-1', | ||
props.className, | ||
props.color ? ( | ||
`text-${props.color}-600 hover:text-${props.color}-900` | ||
) : ( | ||
'text-gray-600 hover:text-gray-900' | ||
) | ||
), [props.color]); | ||
|
||
return ( | ||
<button | ||
className={classCombined} | ||
disabled={props.disabled} | ||
onClick={props.onClick}> | ||
{props.iconLeft && <props.iconLeft className={combineClassNames( | ||
`text-${props.iconColor}-500 group-hover:text-${props.iconColor}-600`, | ||
props.size == 'small' ? ( | ||
'w-4 h-4' | ||
) : ( | ||
props.size == 'large' ? ( | ||
'w-6 h-6' | ||
) : ( | ||
'w-5 h-5' | ||
) | ||
) | ||
)} />} | ||
<span> | ||
{props.text} | ||
</span> | ||
<span className="sr-only">,{props.text}</span> | ||
{props.iconRight && <props.iconRight className={combineClassNames( | ||
`text-${props.iconColor}-500 group-hover:text-${props.iconColor}-600`, | ||
props.size == 'small' ? ( | ||
'w-4 h-4' | ||
) : ( | ||
props.size == 'large' ? ( | ||
'w-6 h-6' | ||
) : ( | ||
'w-5 h-5' | ||
) | ||
) | ||
)} />} | ||
</button >) | ||
} |
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,103 @@ | ||
import { combineClassNames } from "@/submodules/javascript-functions/general"; | ||
import { Tooltip } from '@nextui-org/react' | ||
import { IconCheck } from "@tabler/icons-react"; | ||
import { useState } from "react"; | ||
|
||
interface IconButtonProps { | ||
icon: (props: any) => React.ReactNode; | ||
iconColor?: string; | ||
onClick?: (e?: any) => void; | ||
buttonColor?: string; | ||
disabled?: boolean; | ||
keepOpacity?: boolean; | ||
size?: 'small' | 'medium' | 'large'; | ||
tooltip?: string; | ||
tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right'; | ||
confirm?: boolean; | ||
onMouseDown?: (e?: any) => void; | ||
className?: string; | ||
} | ||
|
||
function InnerButton(props: IconButtonProps) { | ||
const [confirmed, setConfirmed] = useState<boolean>(false); | ||
|
||
return ( | ||
<button | ||
onClick={(e?: any) => { | ||
if (props.onClick) props.onClick(e); | ||
if (props.confirm) { | ||
setConfirmed(true); | ||
setTimeout(() => { | ||
setConfirmed(false); | ||
}, 3000); | ||
} | ||
}} | ||
onMouseDown={props.onMouseDown ? props.onMouseDown : undefined} | ||
className={ | ||
combineClassNames( | ||
'text-sm group flex items-center justify-center rounded-md h-fit hover:shadow-sm transition duration-200 ease-in-out disabled:cursor-not-allowed', | ||
props.className, | ||
props.keepOpacity ? '' : ( | ||
'disabled:opacity-50 ' | ||
), | ||
props.buttonColor ? ( | ||
`border border-${props.buttonColor}-300 bg-${props.buttonColor}-50 hover:bg-${props.buttonColor}-100 hover:border-${props.buttonColor}-400 active:bg-${props.buttonColor}-200 active:border-${props.buttonColor}-500` | ||
) : ( | ||
'border bg-white border-gray-200 hover:bg-gray-50 hover:border-gray-300 active:bg-gray-100 active:border-gray-400' | ||
), | ||
props.size == 'small' ? ( | ||
'p-1' | ||
) : ( | ||
props.size == 'large' ? ( | ||
'p-2' | ||
) : ( | ||
'p-1.5' | ||
) | ||
) | ||
) | ||
} | ||
disabled={props.disabled} | ||
> | ||
{confirmed ? ( | ||
<IconCheck | ||
className={combineClassNames( | ||
`text-green-500 group-hover:text-green-600`, | ||
props.size == 'small' ? ( | ||
'w-4 h-4' | ||
) : ( | ||
props.size == 'large' ? ( | ||
'w-6 h-6' | ||
) : ( | ||
'w-5 h-5' | ||
) | ||
) | ||
)} | ||
/> | ||
) : ( | ||
<props.icon className={combineClassNames( | ||
`text-${props.iconColor}-500 group-hover:text-${props.iconColor}-600`, | ||
props.size == 'small' ? ( | ||
'w-4 h-4' | ||
) : ( | ||
props.size == 'large' ? ( | ||
'w-6 h-6' | ||
) : ( | ||
'w-5 h-5' | ||
) | ||
) | ||
)} /> | ||
)} | ||
|
||
</button> | ||
) | ||
} | ||
|
||
export default function IconButton(props: IconButtonProps) { | ||
return props.disabled ? ( | ||
<InnerButton {...props} /> | ||
) : ( | ||
<Tooltip color="invert" content={props.tooltip} placement={props.tooltipPlacement || "bottom"} > | ||
<InnerButton {...props} /> | ||
</Tooltip> | ||
) | ||
} |
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
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.