Skip to content

Commit

Permalink
Merge pull request #7 from InteractionDesignFoundation/withoutCardSty…
Browse files Browse the repository at this point in the history
…les-option

Add an option to don't use standard Nova card styling (background, padding, etc)
  • Loading branch information
lptn authored Dec 9, 2019
2 parents 04f1463 + 9fab1d0 commit 356f156
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@ public function cards()

### Options
- Set content
- `->html('string')`: Set HTML or plain content.
- `->markdown('string')`: Set Markdown content that will be converted into HTML.
- `->html('<h1>Hello!</h1>')`: Set HTML or plain content.
- `->markdown('# Hello!')`: Set Markdown content that will be converted into HTML.
- `->view('path.to.view', [])`: Specify blade view file and optionally pass an array of data to view.
- Styling
- `->center(boolean)`: Center card's content.
- `->center(false)`: Center card's content. `false` by default.
- `->withoutCardStyles(true)`: Whether to use standard Nova Card styles for a card (background, padding, etc). `false` by default.


### Changelog
## Why this package?
There are a few packages with similar functionality.
Our package provides an API to cover all cases covered by these packages plus additionally provides some unique features like:
- markdown support
- easy switch between class Nova-card look and raw-HTML look
- Simple, Laravel-like API

## Changelog

Please see [Releases](https://github.com/InteractionDesignFoundation/nova-html-card/releases) for more information on what has changed recently.

Expand Down
2 changes: 1 addition & 1 deletion dist/js/card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"/js/card.js": "/js/card.js?id=3f77fbcf19a5dc9cd000"
"/js/card.js": "/js/card.js?id=a9bc40bde6cb473bb382"
}
51 changes: 26 additions & 25 deletions resources/js/components/Card.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
<template>
<card class="flex flex-col justify-center htmlCard" :class="cardClassList">
<div v-if="card.withoutCardStyles" class="htmlCard" :class="cardClassList">
<div v-html="card.content" class="htmlCard__content">
</div>
</div>

<card v-else class="htmlCard htmlCard--hasDefaultHeight" :class="cardClassList">
<div class="px-3 py-3">
<section v-html="card.content" class="htmlCard__content">
</section>
<div v-html="card.content" class="htmlCard__content">
</div>
</div>
</card>
</template>

<script>
export default {
props: [
'card',
],
computed: {
textClassList() {
return this.card.center ? 'text-center' : '';
},
cardClassList() {
const classes = [];
if (this.card.center) {
classes.push('items-center');
}
export default {
props: [
'card',
],
computed: {
cardClassList() {
let classes = '';
if (this.card.center) {
classes += ' flex flex-col justify-center text-center';
}
return classes.join(' ');
},
},
mounted() {
//
},
}
return classes;
},
}
}
</script>

<style>
Expand All @@ -38,8 +37,10 @@
</style>

<style scoped>
.card-panel {
min-height: 150px;
.htmlCard {
height: auto;
}
.htmlCard--hasDefaultHeight {
min-height: 150px;
}
</style>
19 changes: 16 additions & 3 deletions src/HtmlCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct($component = null)

$this->withMeta([
'center' => false,
'withoutCardStyles' => false,
'content' => '',
]);
}
Expand Down Expand Up @@ -80,12 +81,24 @@ public function view(string $view, array $viewData = [])
/**
* Center card's content
*
* @param bool $boolean
* @param bool $centerContent
*
* @return HtmlCard
*/
public function center($boolean = true)
public function center(bool $centerContent = true)
{
return $this->withMeta(['center' => $boolean]);
return $this->withMeta(['center' => $centerContent]);
}

/**
* Whether to use standard Nova Card styles for a card (background, padding, etc)
*
* @param bool $withoutStyles
*
* @return HtmlCard
*/
public function withoutCardStyles(bool $withoutStyles = true)
{
return $this->withMeta(['withoutCardStyles' => $withoutStyles]);
}
}

0 comments on commit 356f156

Please sign in to comment.