docbrown/app/javascript/crayons/CTAs/CTA.jsx
ludwiczakpawel 878c27f9b0
Crayons: buttons followup (#15720)
* init

* whoops

* components update

* components update

* classes

* variables

* focus

* test

* spec

* test

* adjust colors and variables

* buttons colors

* Update app/javascript/crayons/CTAs/CTA.jsx

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* proptype

* remove duplicated tests now in Cypress, enhance Cypress nav menu tests

* premove unneeded viewport in test

* remove focus check for now

* classnames

* Update app/javascript/crayons/CTAs/__stories__/CTAs.mdx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/crayons/CTAs/__stories__/CTAs.mdx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* better contrast

* classname

* add secondary button

* variants + docs

* docs updates

* radius-full

* variants oneof

* the?

* default values + extra stories

* Apply suggestions from code review

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>
2021-12-14 14:43:41 +01:00

47 lines
1.1 KiB
JavaScript

import { h } from 'preact';
import PropTypes from 'prop-types';
import classNames from 'classnames/bind';
import { defaultChildrenPropTypes } from '../../common-prop-types/default-children-prop-types';
import { Icon } from '@crayons';
export const CTA = (props) => {
const {
children,
href = '#',
variant = 'default',
icon,
className,
...otherProps
} = props;
const classes = classNames('c-cta', {
[`c-cta--${variant}`]: variant && variant !== 'default',
'c-cta--icon-left': icon && children,
[className]: className,
});
return (
<a href={href} className={classes} {...otherProps}>
{icon && (
<Icon
src={icon}
aria-hidden="true"
focusable="false"
className="c-cta__icon"
/>
)}
{children}
</a>
);
};
CTA.displayName = 'CTA';
CTA.propTypes = {
variant: PropTypes.oneOf(['default', 'branded']),
rounded: PropTypes.bool,
href: PropTypes.string.isRequired,
className: PropTypes.string,
children: defaultChildrenPropTypes.isRequired,
icon: PropTypes.elementType,
};