Skip to content

Commit 1ff2070

Browse files
feat(molecules): btn-link puede ser un elemento a (#614)
1 parent 9e9ecb1 commit 1ff2070

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/documentation/pages/Molecules/Buttons.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,25 @@ export const Buttons = (): JSX.Element => {
112112
</BtnTertiary>
113113
</ListComponent>
114114
<Code text="<BtnTertiary activeWhenPress iconCustom={<GoAhead />} >custom</BtnTertiary>" />
115+
116+
<MyTittle>BtnLink</MyTittle>
117+
<MyText>
118+
El <code>BtnLink</code> tiene la opción de ser un elemento (<code>button</code>) o un
119+
elemento (<code>a</code>), si la elección es esto último es necesario pasarle la url que
120+
desea abrir con (<code>href</code>), por defecto en una pestaña nueva.
121+
</MyText>
122+
<ListComponent>
123+
<BtnLink>Button</BtnLink>
124+
<BtnLink as="a" href="https://ui-kit.eclass.com/">
125+
Enlace ui-kit
126+
</BtnLink>
127+
</ListComponent>
128+
<Code text="<BtnLink>Button</BtnLink>" />
129+
<Code
130+
text={`<BtnLink as="a" href="https://ui-kit.eclass.com/">
131+
Enlace ui-kit
132+
</BtnLink>`}
133+
/>
115134
</>
116135
)
117136
}

src/molecules/Buttons/BtnLink.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,33 @@ import { Box } from '@chakra-ui/react'
44
export interface props {
55
children?: React.ReactNode
66
m?: string
7+
as?: 'button' | 'a'
78
onClick?: (e: React.MouseEvent<HTMLElement>) => void
89
id?: string
10+
href?: string
911
}
1012

11-
export function BtnLink({ children, m = '0', onClick, id }: props): JSX.Element {
13+
export function BtnLink({
14+
children,
15+
m = '0',
16+
onClick,
17+
id,
18+
as = 'button',
19+
href = '',
20+
}: props): JSX.Element {
21+
const typeButton = {
22+
button: {
23+
onClick,
24+
},
25+
a: {
26+
href,
27+
target: '_blank',
28+
},
29+
}
30+
1231
return (
1332
<Box
14-
as="button"
33+
as={as}
1534
id={id}
1635
backgroundColor="transparent"
1736
borderStyle="none"
@@ -26,11 +45,11 @@ export function BtnLink({ children, m = '0', onClick, id }: props): JSX.Element
2645
textDecorationLine="underline"
2746
color={vars('colors-main-deepSkyBlue')}
2847
m={m}
29-
onClick={onClick}
3048
_hover={{
3149
color: vars('colors-neutral-darkCharcoal'),
3250
cursor: 'pointer',
3351
}}
52+
{...typeButton[as]}
3453
>
3554
{children}
3655
</Box>

0 commit comments

Comments
 (0)