|
| 1 | +# LinkCard Component |
| 2 | + |
| 3 | +The LinkCard component displays links with associated descriptions in a visually appealing card format. |
| 4 | +It supports responsive design and automatically truncates long descriptions based on the viewport width. |
| 5 | + |
| 6 | +## Features |
| 7 | + |
| 8 | +- Displays a link with a title and description |
| 9 | +- Responsive design that adapts to different screen sizes |
| 10 | +- Automatic truncation of long descriptions with "Show More/Less" toggle |
| 11 | +- Properly formats text with line breaks |
| 12 | +- Visual feedback on hover (elevation and shadow changes) |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +```jsx |
| 17 | +import LinkCard from '../components/LinkCard'; |
| 18 | + |
| 19 | +function MyComponent() { |
| 20 | + return ( |
| 21 | + <LinkCard |
| 22 | + href="https://example.com" |
| 23 | + text="Example Website" |
| 24 | + description="This is a description of the example website. It can be multiple lines and will be truncated if it's too long for the current screen size." |
| 25 | + className="custom-class" // Optional |
| 26 | + /> |
| 27 | + ); |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +## Props |
| 32 | + |
| 33 | +| Prop | Type | Required | Default | Description | |
| 34 | +| ------------- | ------ | -------- | -------------------- | ---------------------------------------------------- | |
| 35 | +| `href` | string | Yes | - | The URL that the link points to | |
| 36 | +| `text` | string | Yes | - | The text content/title of the link | |
| 37 | +| `description` | string | Yes | - | A description of the link that appears below it | |
| 38 | +| `className` | string | No | 'link-card--default' | Additional CSS class names to apply to the component | |
| 39 | + |
| 40 | +## Responsive Behavior |
| 41 | + |
| 42 | +The component automatically adjusts the maximum number of visible characters in the description based on the viewport width: |
| 43 | + |
| 44 | +- Small screens (mobile): 300 characters |
| 45 | +- Medium screens (tablets): 500 characters |
| 46 | +- Large screens (desktops): 800 characters |
| 47 | + |
| 48 | +When a description exceeds these limits, a "Show More" button appears to let users expand the text. |
| 49 | + |
| 50 | +## Styling |
| 51 | + |
| 52 | +The component uses the `LinkCard.scss` file for styling. You can customize the appearance by: |
| 53 | + |
| 54 | +1. Modifying `LinkCard.scss` directly |
| 55 | +2. Passing a custom `className` prop |
| 56 | +3. Overriding the default styles in your own stylesheet |
| 57 | + |
| 58 | +## Dependencies |
| 59 | + |
| 60 | +- React |
| 61 | +- PropTypes |
| 62 | +- Internal configuration from `config.js` for responsive breakpoints |
| 63 | + |
| 64 | +## Internal Helpers |
| 65 | + |
| 66 | +The component uses a `renderTextWithLineBreaks` utility function to properly format text with line breaks, converting newline characters into React's `<br />` elements. |
| 67 | + |
| 68 | +## Accessibility |
| 69 | + |
| 70 | +The component follows accessibility best practices: |
| 71 | + |
| 72 | +- "Show More/Less" button includes `aria-expanded` attribute |
| 73 | +- Toggle button has `aria-controls` attribute |
| 74 | +- Interactive elements are keyboard navigable |
| 75 | +- Sufficient color contrast for text elements |
| 76 | + |
| 77 | +### Custom Styling Example |
| 78 | + |
| 79 | +```scss |
| 80 | +// In your custom stylesheet |
| 81 | +.my-custom-link-card { |
| 82 | + // Custom styles here |
| 83 | + background-color: #f5f5f5; |
| 84 | + border-left: 3px solid #0066cc; |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +```jsx |
| 89 | +<LinkCard |
| 90 | + href="https://example.com" |
| 91 | + text="Custom Styled Card" |
| 92 | + description="This card has custom styling applied." |
| 93 | + className="my-custom-link-card" |
| 94 | +/> |
| 95 | +``` |
0 commit comments