From fb2f6645cce03f82b0a37eb0e72ab8d0d1b523e9 Mon Sep 17 00:00:00 2001 From: Aminejv Date: Wed, 22 Dec 2021 17:24:06 +0100 Subject: [PATCH] feat(Buttons): forward ref --- components/system/components/Buttons.js | 466 ++++++++++++------------ 1 file changed, 223 insertions(+), 243 deletions(-) diff --git a/components/system/components/Buttons.js b/components/system/components/Buttons.js index 4d327d8b..732c7174 100644 --- a/components/system/components/Buttons.js +++ b/components/system/components/Buttons.js @@ -2,10 +2,9 @@ import * as React from "react"; import * as Constants from "~/common/constants"; import { css } from "@emotion/react"; - import { LoaderSpinner } from "~/components/system/components/Loaders"; -const STYLES_BUTTON = ` +const STYLES_BUTTON = css` box-sizing: border-box; border-radius: 12px; outline: 0; @@ -54,83 +53,79 @@ const STYLES_BUTTON_PRIMARY_TRANSPARENT = css` color: ${Constants.system.blue}; `; -export const ButtonPrimary = ({ - children, - css, - style, - full, - transparent, - loading, - label, - type, - ...props -}) => { - if (loading) { +export const ButtonPrimary = React.forwardRef( + ({ children, css, style, full, transparent, loading, label, type, ...props }, ref) => { + if (loading) { + return ( + + ); + } + + if (type === "label") { + return ( + + ); + } + + if (type === "link") { + return ( + + {children} + + ); + } + + if (props.disabled) { + return ( + + ); + } + return ( - ); - } - - if (type === "label") { - return ( - - ); - } - - if (type === "link") { - return ( - - {children} - - ); - } - - if (props.disabled) { - return ( - ); } +); - return ( - - ); -}; - -export const ButtonPrimaryFull = (props) => { - return ; -}; +export const ButtonPrimaryFull = React.forwardRef((props, ref) => { + return ; +}); const STYLES_BUTTON_SECONDARY = css` ${STYLES_BUTTON} @@ -157,66 +152,62 @@ const STYLES_BUTTON_SECONDARY_TRANSPARENT = css` color: ${Constants.system.grayLight2}; `; -export const ButtonSecondary = ({ - children, - css, - style, - full, - transparent, - loading, - label, - type, - ...props -}) => { - if (loading) { +export const ButtonSecondary = React.forwardRef( + ({ children, css, style, full, transparent, loading, label, type, ...props }, ref) => { + if (loading) { + return ( + + ); + } + + if (type === "label") { + return ( + + ); + } + + if (type === "link") { + return ( + + {children} + + ); + } + return ( ); } - - if (type === "label") { - return ( - - ); - } - - if (type === "link") { - return ( - - {children} - - ); - } - - return ( - - ); -}; +); export const ButtonSecondaryFull = (props) => { return ; @@ -233,11 +224,6 @@ const STYLES_BUTTON_TERTIARY = css` :hover { background-color: #fcfcfc; } - - :focus { - outline: 0; - border: 0; - } `; const STYLES_BUTTON_TERTIARY_TRANSPARENT = css` @@ -248,69 +234,65 @@ const STYLES_BUTTON_TERTIARY_TRANSPARENT = css` color: ${Constants.system.grayLight2}; `; -export const ButtonTertiary = ({ - children, - css, - style, - full, - transparent, - loading, - label, - type, - ...props -}) => { - if (loading) { +export const ButtonTertiary = React.forwardRef( + ({ children, css, style, full, transparent, loading, label, type, ...props }, ref) => { + if (loading) { + return ( + + ); + } + + if (type === "label") { + return ( + + ); + } + + if (type === "link") { + return ( + + {children} + + ); + } + return ( ); } +); - if (type === "label") { - return ( - - ); - } - - if (type === "link") { - return ( - - {children} - - ); - } - - return ( - - ); -}; - -export const ButtonTertiaryFull = (props) => { - return ; -}; +export const ButtonTertiaryFull = React.forwardRef((props, ref) => { + return ; +}); const STYLES_BUTTON_DISABLED = css` ${STYLES_BUTTON} @@ -332,22 +314,25 @@ const STYLES_BUTTON_DISABLED_TRANSPARENT = css` color: ${Constants.system.gray}; `; -export const ButtonDisabled = ({ children, css, style, full, label, ...props }) => { - return ( - - ); -}; +export const ButtonDisabled = React.forwardRef( + ({ children, css, style, full, label, ...props }, ref) => { + return ( + + ); + } +); -export const ButtonDisabledFull = (props) => { - return ; -}; +export const ButtonDisabledFull = React.forwardRef((props, ref) => { + return ; +}); const STYLES_BUTTON_WARNING = css` ${STYLES_BUTTON} @@ -380,69 +365,64 @@ const STYLES_BUTTON_WARNING_TRANSPARENT = css` color: ${Constants.system.red}; `; -export const ButtonWarning = ({ - children, - css, - style, - full, - transparent, - type, - disabled, - loading, - label, - ...props -}) => { - if (loading) { +export const ButtonWarning = React.forwardRef( + ({ children, css, style, full, transparent, type, disabled, loading, label, ...props }, ref) => { + if (loading) { + return ( + + ); + } + + if (type === "label") { + return ( + + ); + } + + if (disabled) { + return ( + + ); + } + return ( - ); - } - - if (type === "label") { - return ( - - ); - } - - if (disabled) { - return ( - ); } +); - return ( - - ); -}; - -export const ButtonWarningFull = (props) => { - return ; -}; +export const ButtonWarningFull = React.forwardRef((props, ref) => { + return ; +});