1
0
Fork 0
mirror of synced 2024-10-01 01:28:51 +13:00

Merge pull request #161 from Conor-Mack/feature/card

Completed Material Card Component
This commit is contained in:
Conor_Mack 2020-03-20 14:57:36 +00:00 committed by GitHub
commit cc2e6ce1bb
19 changed files with 337 additions and 11 deletions

View file

@ -111,6 +111,52 @@
},
"tags": []
},
"Card": {
"name": "Card",
"description": "A Material Card container. Accepts CardHeader, CardBody and CardFooter as possible children",
"props": {
"width": "string",
"height": "string",
"variant": {
"type": "options",
"options": ["standard", "outlined"],
"default": "standard"
}
}
},
"CardBody": {
"name": "CardBody",
"description": "A Material CardBody component. Contains the main content of a Material Card component",
"props": {
"onClick": "event"
}
},
"CardImage": {
"name": "CardImage",
"description": "An image component for the Material Card component",
"props": {
"displayHorizontal": "bool",
"url": "string",
"title": "string",
"subtitle": "string"
}
},
"CardHeader": {
"name": "CardHeader",
"description": "Displays a icon, title and subtitle above main body of the Material Card component",
"props": {
"title": "string",
"subtitle": "string",
"icon": "string"
}
},
"CardFooter": {
"name": "CardFooter",
"description": "Displays buttons / icon buttons as actions for the Material Card component",
"props": {
"padding": "string"
}
},
"Checkbox": {
"name": "Checkbox",
"description": "A Material Design checkbox. Supports aligning label before or after checkbox.",

View file

@ -50,5 +50,7 @@
"version": "0.0.27",
"license": "MIT",
"gitHead": "72a77a035eb7c1443b079bf93c29b3e5fe02094e",
"dependencies": {}
"dependencies": {
"@material/card": "4.0.0"
}
}

View file

@ -1,5 +1,5 @@
<script>
import { setContext, getContext } from "svelte"
import { onMount } from "svelte"
import Icon from "../Common/Icon.svelte"
import ripple from "../Common/Ripple.js"
import ClassBuilder from "../ClassBuilder.js"
@ -22,12 +22,18 @@
export let _bb
onMount(() => {
let ctx = _bb.getContext("BBMD:button:context")
extras = [ctx]
})
let extras = ""
let modifiers = {}
let customs = { size, colour }
if (!href) modifiers = { variant }
let props = { modifiers, customs }
let props = { modifiers, customs, extras }
let blockClasses = cb.build({ props })
const labelClass = cb.elem("label")

View file

@ -0,0 +1,34 @@
<script>
import CardHeader from "./CardHeader.svelte"
import CardBody from "./CardBody.svelte"
import CardImage from "./CardImage.svelte"
import CardFooter from "./CardFooter.svelte"
import { H2, H6, Body2 } from "../Typography"
import { Button } from "../Button"
import { IconButton } from "../IconButton"
import ClassBuilder from "../ClassBuilder.js"
export let width = "350px"
export let height = "auto"
export let variant = "standard"
export let _bb
let card
const cb = new ClassBuilder("card", ["standard"])
$: modifiers = { variant }
$: props = { modifiers }
$: cardClass = cb.build({ props })
$: safeWidth = width !== "auto" && !/px$/.test(width) ? `${width}px` : width
$: safeHeight =
height !== "auto" && !/px$/.test(height) ? `${width}px` : height
$: card && _bb.attachChildren(card)
</script>
<div
bind:this={card}
style={`width: ${safeWidth}; height: ${safeHeight}`}
class={cardClass} />

View file

@ -0,0 +1,10 @@
<script>
export let _bb
export let onClick = () => {}
let cardBody
$: cardBody && _bb.attachChildren(cardBody)
</script>
<div bind:this={cardBody} class="mdc-card__primary-action" on:click={onClick} />

View file

@ -0,0 +1,31 @@
<script>
import { onMount } from "svelte"
let cardFooter
export let _bb
export let padding = "5px"
onMount(() => {
_bb.setContext(
"BBMD:icon-button:context",
"mdc-card__action mdc-card__action--icon"
)
_bb.setContext(
"BBMD:button:context",
"mdc-card__action mdc-card__action--button"
)
})
$: cardFooter && _bb.attachChildren(cardFooter)
</script>
<div
bind:this={cardFooter}
style={`padding: ${padding}`}
class="mdc-card__actions bbmd-card__actions" />
<style>
.bbmd-card__actions {
display: flex;
flex-flow: row wrap;
}
</style>

View file

@ -0,0 +1,44 @@
<script>
import { H6, Sub2 } from "../Typography"
import Icon from "../Common/Icon.svelte"
export let _bb
export let title = ""
export let subtitle = ""
export let icon = ""
$: useIcon = !!icon
$: useSubtitle = !!subtitle
</script>
<div class="card-header">
{#if useIcon}
<div class="card-header__icon">
<Icon {icon} />
</div>
{/if}
<div class="card-header__title">
<H6 text={title} />
{#if useSubtitle}
<Sub2 text={subtitle} />
{/if}
</div>
</div>
<style>
.card-header {
display: flex;
flex-flow: row nowrap;
padding: 10px;
}
.card-header__icon {
flex: 0;
padding: 10px;
}
.card-header__title {
display: flex;
flex-flow: column nowrap;
flex: 1;
}
</style>

View file

@ -0,0 +1,62 @@
<script>
import { H6, Sub2 } from "../Typography"
export let _bb
export let displayHorizontal = false //aligns image on row with title and subtitle text
export let url = ""
export let title = ""
export let subtitle = ""
$: useTitle = !!title
$: useSubTitle = !!subtitle
</script>
{#if !displayHorizontal}
<div
class="my-card__media mdc-card__media mdc-card__media--16-9"
style={`background-image: url(${url})`}>
<div class="mdc-card__media-content bbmd-card-media__content">
{#if useTitle}
<H6 text={title} verticalMargin={0} horizontalMargin={10} />
{#if useSubTitle}
<Sub2 text={subtitle} horizontalMargin={10} />
{/if}
{/if}
</div>
</div>
{:else}
<div class="bbmd-card--horizontal">
<div
class="mdc-card__media mdc-card__media mdc-card__media--square
bbmd-card--horizontal-image"
style={`background-image: url(${url})`} />
<div class="bbmd-card--horizontal-text">
{#if useTitle}
<H6 text={title} verticalMargin={0} horizontalMargin={10} />
{#if useSubTitle}
<Sub2 text={subtitle} horizontalMargin={10} />
{/if}
{/if}
</div>
</div>
{/if}
<style>
.bbmd-card--horizontal {
display: flex;
flex-flow: row nowrap;
}
.bbmd-card--horizontal-image {
flex: 0 0 110px;
}
.bbmd-card--horizontal-text {
flex: 1;
padding: 10px 5px;
}
.bbmd-card-media__content {
top: 125px;
color: white;
}
</style>

View file

@ -0,0 +1 @@
@import "@material/card/mdc-card.scss"

View file

@ -0,0 +1,7 @@
import "./_styles.scss"
export { default as Card } from "./Card.svelte"
export { default as CardBody } from "./CardBody.svelte"
export { default as CardFooter } from "./CardFooter.svelte"
export { default as CardHeader } from "./CardHeader.svelte"
export { default as CardImage } from "./CardImage.svelte"

View file

@ -1,6 +1,4 @@
<script>
import { getContext } from "svelte"
export let icon = ""
export let context = ""

View file

@ -25,6 +25,7 @@
let navDate = new Date()
const weekdayMap = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
export let _bb
export let date = new Date()
export let label = ""
export let onSelect = selectedDate => {}
@ -105,13 +106,13 @@
<div class="calendar-container">
<div class="month-picker">
<div>
<IconButton icon="chevron_left" onClick={subtractMonth} />
<IconButton icon="chevron_left" {_bb} onClick={subtractMonth} />
</div>
<div class="centreText">
<Body1 text={monthAndYear} />
</div>
<div>
<IconButton icon="chevron_right" onClick={addMonth} />
<IconButton icon="chevron_right" {_bb} onClick={addMonth} />
</div>
</div>
<div class="week-days">

View file

@ -1,4 +1,5 @@
<script>
import { onMount } from "svelte"
import ripple from "../Common/Ripple.js"
import ClassBuilder from "../ClassBuilder.js"
@ -15,6 +16,14 @@
export let onIcon = "" //on state icon for toggle button
export let size = "medium"
onMount(() => {
let ctx = !!_bb ? _bb.getContext("BBMD:icon-button:context") : ""
//It isn't possible to use context within nested components as they do not have their own _bb instance (has to be passed down from parent component). This allows context to be passed as props
if (!context && !!ctx) {
context = ctx
}
})
function onButtonClick() {
open = !open
onClick()

View file

@ -19,6 +19,7 @@
Select,
DatePicker,
IconButton,
Card,
} = props
let currentComponent
@ -38,6 +39,7 @@
Radiobuttongroup,
DatePicker,
IconButton,
Card,
],
},
}

View file

@ -210,11 +210,59 @@ export const props = {
_component: "@budibase/materialdesign-components/DatePicker",
_children: [],
label: "Date of Admission",
onSelect: date => console.log("SELECTED DATE", date)
onSelect: date => console.log("SELECTED DATE", date),
},
IconButton: {
_component: "@budibase/materialdesign-components/IconButton",
_children: [],
icon: "calendar_today",
},
Card: {
_id: "card",
width: "400",
_component: "@budibase/materialdesign-components/Card",
_children: [
{
_id: "cardbody",
_component: "@budibase/materialdesign-components/CardBody",
onClick: () => alert`Hi`,
_children: [
{
_id: "cardimage1",
_component: "@budibase/materialdesign-components/CardImage",
_children: [],
displayHorizontal: true,
url: "https://picsum.photos/350",
title: "Our New World",
subtitle: "Out now in cinemas",
},
],
},
{
_component: "@budibase/materialdesign-components/CardFooter",
_children: [
{
_component: "@budibase/materialdesign-components/Button",
text: "Save",
},
{
_component: "@budibase/materialdesign-components/Button",
text: "Cancel",
},
{
_component: "@budibase/materialdesign-components/IconButton",
icon: "3d_rotation",
},
{
_component: "@budibase/materialdesign-components/IconButton",
icon: "accessibility",
},
{
_component: "@budibase/materialdesign-components/IconButton",
icon: "alarm_on",
},
],
},
],
},
}

View file

@ -1,5 +1,11 @@
<script>
export let text = ""
export let verticalMargin = 0
export let horizontalMargin = 0
</script>
<span class="mdc-typography--body2">{text}</span>
<span
style={`margin: ${verticalMargin}px ${horizontalMargin}px`}
class="mdc-typography--body2">
{text}
</span>

View file

@ -1,5 +1,11 @@
<script>
export let text = ""
export let verticalMargin = 5
export let horizontalMargin = 0
</script>
<h6 class="mdc-typography--headline6">{text}</h6>
<h6
style={`margin: ${verticalMargin}px ${horizontalMargin}px`}
class="mdc-typography--headline6">
{text}
</h6>

View file

@ -1,5 +1,11 @@
<script>
export let text = ""
export let verticalMargin = 5
export let horizontalMargin = 0
</script>
<span class="mdc-typography--subtitle2">{text}</span>
<span
style={`margin: ${verticalMargin}px ${horizontalMargin}px`}
class="mdc-typography--subtitle2">
{text}
</span>

View file

@ -21,3 +21,10 @@ export { Menu } from "./Menu"
export { Select } from "./Select"
export { DatePicker } from "./DatePicker"
export { IconButton } from "./IconButton"
export { Card } from "./Card"
export { CardHeader } from "./Card"
export { CardImage } from "./Card"
export { CardBody } from "./Card"
export { CardFooter } from "./Card"