-
Notifications
You must be signed in to change notification settings - Fork 0
#1076 - Egen komponent for Card i designsystemet #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rebalv
wants to merge
17
commits into
main
Choose a base branch
from
1067-egen-card-komponent-i-designsystemet
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
823dfd9
#1076 - feat: first simple version of card
rebalv 38c65fa
#1067 - feat: added slots for other and subtitle + new css
rebalv d045465
#1067 - feat: parameter for href clickable cards
rebalv 15816c2
#1067 - chore: avoid link lines under the text
rebalv 930c247
#1067 - chore: improved css for card
rebalv eda1755
#1067 - feat: added documentation file for card
rebalv 1c9ee31
#1067 - fix: linting
rebalv e4d3917
#1067 - feat: egne tokens for title og tekst
rebalv 3e85a17
#1067 - chore: ta i bruk tokens for titles
rebalv 539a6cf
#1067 - chore: la til mer font styling for mobil og desktop text
rebalv a5a29b1
Merge branch 'main' into 1067-egen-card-komponent-i-designsystemet
rebalv 5ef59e4
#1067 - chore: linting
rebalv 00dd855
#1067 - chore: 100% height of cards and spesific height for images
rebalv 81a79eb
#1067 - feat: separate css files for typography classes
rebalv c6d8baf
#1067 - feat: added typography classes to global styles
rebalv b03d8be
#1067 - chore: removed max width for the cards
rebalv bf2f81b
#1067 - feat: removed href and changed naming
rebalv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { Canvas, Meta, Source, Subtitle, Title } from "@storybook/blocks"; | ||
|
|
||
| import * as stories from "./card.stories"; | ||
|
|
||
| <Meta of={stories} /> | ||
|
|
||
| <Title /> | ||
| <Subtitle> | ||
| A card is used to display content and actions on a single topic. They provide a flexible and extensible content container that groups related information in an easily scannable format. | ||
| </Subtitle> | ||
|
|
||
| ## How to get started | ||
| Start by importing the component. Once imported, the `<cx-card>` component is ready to use. | ||
| ``` ts | ||
| // Web component | ||
| import '@computas/designsystem/card'; | ||
|
|
||
| // React | ||
| import { CxCard } from '@computas/designsystem/card/react'; | ||
| ``` | ||
|
|
||
| ## Default | ||
| A card can consist of an **image**, **title**, **subtitle** and **body content**. The **title** and **image** can be set as properties, while **subtitle** and **body** use slots for maximum flexibility. | ||
| <Canvas of={stories.Default} /> | ||
|
|
||
| ## Content slots | ||
| The card supports several content slots for customization: | ||
|
|
||
| - **`subtitle`** - For metadata like time, location, or categories | ||
| - **`body`** - For additional content like buttons, tags, or other actions | ||
|
|
||
| <Source | ||
| code={`<cx-card image="https://example.com/image.jpg" title="Card Title"> | ||
| <span slot="subtitle">14:00 - 16:00 • Oslo, Norway</span> | ||
| <button slot="body" class="cx-btn__secondary">Learn more</button> | ||
| </cx-card>`} | ||
| /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { Meta, StoryObj } from '@storybook/web-components'; | ||
| import { html } from 'lit'; | ||
| import './card.js'; | ||
|
|
||
| const meta: Meta = { | ||
| title: 'Components/Card', | ||
| component: 'cx-card', | ||
| parameters: { | ||
| layout: 'centered', | ||
| }, | ||
| argTypes: { | ||
| title: { control: 'text' }, | ||
| image: { control: 'text' }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| title: 'Card Title', | ||
| image: 'https://picsum.photos/500/220', | ||
| }, | ||
| render: (args) => html` | ||
| <cx-card title="${args.title}" image="${args.image}"> | ||
| <span slot="subtitle">14:00 - 16:00 • Oslo, Norway</span> | ||
| <div slot="body"> | ||
| <p>Additional body content</p> | ||
| </div> | ||
| </cx-card> | ||
| `, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import { LitElement, css, html, unsafeCSS } from 'lit'; | ||
| import { customElement, property } from 'lit/decorators.js'; | ||
| import text1CSS from '../../global-css/typography/text-1.css?inline'; | ||
| import text4CSS from '../../global-css/typography/text-4.css?inline'; | ||
|
|
||
| @customElement('cx-card') | ||
| export class Card extends LitElement { | ||
| static styles = [ | ||
| unsafeCSS(text1CSS), | ||
| unsafeCSS(text4CSS), | ||
| css` | ||
| .card { | ||
| position: relative; | ||
| height: 100%; | ||
| width: 100%; | ||
| border-radius: 24px; | ||
| overflow: hidden; | ||
| display: flex; | ||
| flex-direction: column; | ||
| text-decoration: none; | ||
| color: inherit; | ||
| } | ||
|
|
||
| .card-image { | ||
| width: 100%; | ||
| height: 192px; | ||
| position: relative; | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .card-image img { | ||
| width: 100%; | ||
| height: 100%; | ||
| object-fit: cover; | ||
| transition: filter 0.3s ease; | ||
| } | ||
|
|
||
| /* Blue filter on img for hover */ | ||
| .card-image::after { | ||
| content: ""; | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| mix-blend-mode: multiply; | ||
| background: var(--cx-color-background-accent-5); | ||
| opacity: 0; | ||
| transition: opacity 0.3s ease; | ||
| } | ||
|
|
||
| .card-info { | ||
| flex: 1; | ||
| padding: var(--cx-spacing-6); | ||
| color: var(--cx-color-text-primary); | ||
| background-color: var(--cx-color-background-accent-1-soft); | ||
| display: flex; | ||
| flex-direction: column; | ||
| height: 100%; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| .card-subtitle { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| color: var(--cx-color-text-less-important); | ||
| gap: var(--cx-spacing-2); | ||
| margin-bottom: var(--cx-spacing-4); | ||
| } | ||
|
|
||
| .card-title { | ||
| display: -webkit-box; | ||
| -webkit-box-orient: vertical; | ||
| -webkit-line-clamp: 2; | ||
| line-clamp: 2; | ||
| overflow: hidden; | ||
| margin-bottom: var(--cx-spacing-2); | ||
| align-content: center; | ||
| } | ||
|
|
||
| .card-body { | ||
| display: flex; | ||
| gap: var(--cx-spacing-2); | ||
| flex-wrap: wrap; | ||
| margin-top: auto; | ||
| } | ||
|
|
||
| /* Hover effects - only on image */ | ||
| .card:hover .card-image img { | ||
| filter: grayscale(1); | ||
| } | ||
|
|
||
| .card:hover .card-image::after { | ||
| opacity: 1; | ||
| } | ||
|
|
||
| @media (max-width: 750px) { | ||
| .card { | ||
| flex-direction: column; | ||
| height: auto; | ||
| } | ||
|
|
||
| .card-image { | ||
| width: 100%; | ||
| height: 125px; | ||
| } | ||
|
|
||
| .card-info { | ||
| width: 100%; | ||
| padding: var(--cx-spacing-4); | ||
| flex-direction: column-reverse; | ||
| gap: var(--cx-spacing-2); | ||
| box-sizing: border-box; | ||
| } | ||
| } | ||
| `, | ||
| ]; | ||
|
|
||
| @property({ type: String, reflect: true }) | ||
| title = ''; | ||
|
|
||
| @property({ type: String, reflect: true }) | ||
| image = ''; | ||
|
|
||
| render() { | ||
| return html` | ||
| <div class="card"> | ||
| <div class="card-image"> | ||
| ${this.image ? html`<img src="${this.image}" alt="" />` : html`<slot name="image"></slot>`} | ||
| </div> | ||
| <div class="card-info"> | ||
| <div class="card-subtitle cx-text-4"> | ||
| <slot name="subtitle"></slot> | ||
| </div> | ||
| ${ | ||
| this.title | ||
| ? html`<div class="card-title cx-text-1">${this.title}</div>` | ||
| : html`<div class="card-title cx-text-1"><slot name="title"></slot></div>` | ||
| } | ||
| <div class="card-body"> | ||
| <slot name="body"></slot> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `; | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'cx-card': Card; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| .cx-text-1 { | ||
| font-size: 1.5rem; | ||
| font-weight: 400; | ||
| line-height: 1.6; | ||
| } | ||
|
|
||
| :is(p).cx-text-1 { | ||
| max-width: 65ch; | ||
| text-wrap: pretty; | ||
| word-break: auto-phrase; | ||
| } | ||
|
|
||
| .cx-text-clickable-1 { | ||
| font-weight: 500; | ||
| font-size: 1.125rem; | ||
| line-height: 1; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.