|
| 1 | +import React from "react"; |
| 2 | +import { LinkCardTypes } from "../constants/link-card-types"; |
| 3 | +import { StringUtils } from "andculturecode-javascript-core"; |
| 4 | +import { Anchor } from "../../atoms/anchors/anchor"; |
| 5 | +import { Button } from "../../atoms/buttons/button"; |
| 6 | +import { Icon } from "../../atoms/icons/icon"; |
| 7 | +import { Icons } from "../../atoms/constants/icons"; |
| 8 | +import { Paragraph } from "../../atoms/typography/paragraph"; |
| 9 | +import { ParagraphSizes } from "../../atoms/constants/paragraph-sizes"; |
| 10 | + |
| 11 | +// ------------------------------------------------------------------------------------------------- |
| 12 | +// #region Contants |
| 13 | +// ------------------------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +const COMPONENT_CLASS = "c-link-card"; |
| 16 | + |
| 17 | +// #endregion Constants |
| 18 | + |
| 19 | +// ------------------------------------------------------------------------------------------------- |
| 20 | +// #region Interfaces |
| 21 | +// ------------------------------------------------------------------------------------------------- |
| 22 | + |
| 23 | +export interface LinkCardProps { |
| 24 | + children: any; |
| 25 | + iconType?: Icons; |
| 26 | + includeIcon?: boolean; |
| 27 | + label: string; |
| 28 | + onClick?: () => void; |
| 29 | + to?: any; |
| 30 | + type?: LinkCardTypes; |
| 31 | +} |
| 32 | + |
| 33 | +// #endregion Interfaces |
| 34 | + |
| 35 | +// ------------------------------------------------------------------------------------------------- |
| 36 | +// #region Component |
| 37 | +// ------------------------------------------------------------------------------------------------- |
| 38 | + |
| 39 | +const LinkCard: React.FC<LinkCardProps> = (props: LinkCardProps) => { |
| 40 | + const cssClassNames = [COMPONENT_CLASS]; |
| 41 | + if (props.includeIcon) { |
| 42 | + cssClassNames.push("-with-icon"); |
| 43 | + } |
| 44 | + |
| 45 | + const cssClassNamesFlat = cssClassNames.join(" "); |
| 46 | + const iconType = props.iconType ?? Icons.Lightbulb; |
| 47 | + const type = props.type ?? LinkCardTypes.Link; |
| 48 | + |
| 49 | + const renderChildren = () => ( |
| 50 | + <React.Fragment> |
| 51 | + {// if |
| 52 | + props.includeIcon && <Icon type={iconType} />} |
| 53 | + <div className={`${COMPONENT_CLASS}__content`}> |
| 54 | + <Paragraph size={ParagraphSizes.Small}> |
| 55 | + {props.children} |
| 56 | + </Paragraph> |
| 57 | + {// if |
| 58 | + StringUtils.hasValue(props.label) && ( |
| 59 | + <div className={`${COMPONENT_CLASS}__label`}> |
| 60 | + <Paragraph size={ParagraphSizes.XSmall}> |
| 61 | + {props.label} |
| 62 | + </Paragraph> |
| 63 | + </div> |
| 64 | + )} |
| 65 | + </div> |
| 66 | + </React.Fragment> |
| 67 | + ); |
| 68 | + |
| 69 | + return ( |
| 70 | + <div> |
| 71 | + {// if |
| 72 | + type === LinkCardTypes.Button && ( |
| 73 | + <Button |
| 74 | + cssClassName={cssClassNamesFlat} |
| 75 | + onClick={props.onClick}> |
| 76 | + {renderChildren()} |
| 77 | + </Button> |
| 78 | + )} |
| 79 | + {// if |
| 80 | + type === LinkCardTypes.Link && ( |
| 81 | + <Anchor cssClassName={cssClassNamesFlat} to={props.to}> |
| 82 | + {renderChildren()} |
| 83 | + </Anchor> |
| 84 | + )} |
| 85 | + </div> |
| 86 | + ); |
| 87 | +}; |
| 88 | + |
| 89 | +// #endregion Component |
| 90 | + |
| 91 | +// ------------------------------------------------------------------------------------------------- |
| 92 | +// #region Exports |
| 93 | +// ------------------------------------------------------------------------------------------------- |
| 94 | + |
| 95 | +export { LinkCard }; |
| 96 | + |
| 97 | +// #endregion Exports |
0 commit comments