Skip to content

Commit 5b4fd48

Browse files
author
Jason Tame
authored
Merge pull request #18 from InteractionDesignFoundation/html-basic-styling
Add option to include basic styling for HTML elements
2 parents 0c22adc + 4528bae commit 5b4fd48

File tree

7 files changed

+169
-49
lines changed

7 files changed

+169
-49
lines changed

README.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| We stand with Ukraine | 🇺🇦 |
2-
|:---------------------:|:-----|
1+
| We stand with Ukraine | 🇺🇦 |
2+
| :-------------------: | :-- |
33

44
# Nova HTML Card
55

@@ -12,7 +12,6 @@ Adds a card to the Laravel Nova dashboard with any arbitrary HTML content.
1212

1313
![image](https://user-images.githubusercontent.com/5278175/60386958-35899080-9aa5-11e9-8e1f-b29e95c80d2c.png)
1414

15-
1615
## Installation
1716

1817
You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:
@@ -38,37 +37,34 @@ public function cards()
3837
}
3938
```
4039

41-
4240
### Options
4341

44-
- Set content
45-
- `->html('<h1>Hello!</h1>')`: Set HTML or plain content.
46-
- `->markdown('# Hello!')`: Set Markdown content that will be converted into HTML.
47-
- `->view('path.to.view', [])`: Specify blade view file and optionally pass an array of data to view.
48-
- Styling
49-
- `->center(false)`: Center card's content. `false` by default.
50-
- `->withoutCardStyles(true)`: Whether to use standard Nova Card styles for a card (background, padding, etc). `false` by default.
51-
42+
- Set content
43+
- `->html('<h1>Hello!</h1>')`: Set HTML or plain content.
44+
- `->markdown('# Hello!')`: Set Markdown content that will be converted into HTML.
45+
- `->view('path.to.view', [])`: Specify blade view file and optionally pass an array of data to view.
46+
- Styling
47+
- `->center(false)`: Center card's content. `false` by default.
48+
- `->withoutCardStyles(true)`: Whether to use standard Nova Card styles for a card (background, padding, etc). `false` by default.
49+
- `->withBasicStyles()`: Adds some basic styling to the HTML elements in the card. Useful when rendering Markdown.
5250

5351
## Why this package?
5452

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

56+
- Markdown support
57+
- easy switch between class Nova-card look and raw-HTML look
58+
- Simple, Laravel-like API
6159

6260
## Changelog
6361

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

66-
6764
## Contributing
6865

6966
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
7067

71-
7268
## License
7369

7470
The MIT License (MIT). Please see [License File](LICENSE) for more information.

dist/js/card.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"/js/card.js": "/js/card.js?id=591c45f787ce8b18b6c3724b2c083b88"
2+
"/js/card.js": "/js/card.js?id=656041b0c15589bc5890ab8120de6604"
33
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
},
1616
"devDependencies": {
1717
"laravel-mix": "^6.0",
18+
"node-sass": "^8.0.0",
19+
"sass-loader": "^13.2.0",
1820
"vue-loader": "^16.8.3"
1921
},
2022
"dependencies": {

resources/js/components/Card.vue

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
<template>
2-
<div v-if="card.withoutCardStyles" class="htmlCard" :class="cardClassList">
3-
<div v-html="card.content" class="htmlCard__content">
4-
</div>
5-
</div>
2+
<div v-if="card.withoutCardStyles" class="htmlCard" :class="cardClassList">
3+
<CardContent
4+
:content="card.content"
5+
:with-basic-styles="card.withBasicStyles"
6+
/>
7+
</div>
68

7-
<Card v-else class="htmlCard" :class="cardClassList">
8-
<div class="px-3 py-3">
9-
<div v-html="card.content" class="htmlCard__content">
10-
</div>
11-
</div>
12-
</Card>
9+
<Card v-else class="htmlCard" :class="cardClassList">
10+
<div class="px-3 py-3">
11+
<CardContent
12+
:content="card.content"
13+
:with-basic-styles="card.withBasicStyles"
14+
/>
15+
</div>
16+
</Card>
1317
</template>
1418

1519
<script>
16-
export default {
17-
props: [
18-
'card',
19-
],
20-
computed: {
21-
cardClassList() {
22-
let classes = '';
23-
if (this.card.center) {
24-
classes += ' flex flex-col justify-center text-center';
25-
}
20+
import CardContent from './CardContent';
21+
export default {
22+
components: {
23+
CardContent,
24+
},
25+
props: ['card'],
26+
computed: {
27+
cardClassList() {
28+
let classes = '';
29+
if (this.card.center) {
30+
classes += ' flex flex-col justify-center text-center';
31+
}
2632
27-
return classes;
28-
},
29-
},
30-
}
33+
return classes;
34+
},
35+
},
36+
};
3137
</script>
32-
33-
<style>
34-
.htmlCard__content > p:not(:last-child) {
35-
margin-bottom: 1em;
36-
}
37-
</style>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<template>
2+
<div
3+
v-html="content"
4+
class="htmlCard__content"
5+
:class="{htmlCard__basicStyles: withBasicStyles}"
6+
></div>
7+
</template>
8+
9+
<script>
10+
export default {
11+
props: ['content', 'withBasicStyles'],
12+
};
13+
</script>
14+
15+
<style lang="scss">
16+
.htmlCard__content {
17+
p:not(:last-child) {
18+
margin-bottom: 1em;
19+
}
20+
}
21+
22+
.htmlCard__basicStyles {
23+
a {
24+
color: #009cde;
25+
text-decoration: none;
26+
}
27+
28+
a:hover {
29+
text-decoration: underline;
30+
}
31+
32+
p,
33+
blockquote,
34+
ul,
35+
ol,
36+
dl,
37+
table,
38+
pre {
39+
margin: 15px 0;
40+
}
41+
42+
ul,
43+
ol {
44+
padding-left: 30px;
45+
}
46+
47+
li {
48+
list-style: disc;
49+
}
50+
51+
h1 {
52+
font-size: 2.5em;
53+
}
54+
55+
h2 {
56+
font-size: 2em;
57+
}
58+
59+
h3 {
60+
font-size: 1.5em;
61+
}
62+
63+
h4 {
64+
font-size: 1.2em;
65+
}
66+
67+
h5 {
68+
font-size: 1em;
69+
}
70+
71+
h6 {
72+
font-size: 1em;
73+
}
74+
75+
h1,
76+
h2,
77+
h3,
78+
h4,
79+
h5,
80+
h6 {
81+
font-weight: bold;
82+
line-height: 1.7;
83+
margin-bottom: 15px;
84+
}
85+
86+
h1 + p,
87+
h2 + p,
88+
h3 + p {
89+
margin-top: 10px;
90+
}
91+
92+
img {
93+
max-width: 100%;
94+
}
95+
96+
code,
97+
pre {
98+
background-color: #f8f8f8;
99+
border: 1px solid #ddd;
100+
border-radius: 3px;
101+
font-family: Consolas, 'Liberation Mono', Courier, monospace;
102+
font-size: 12px;
103+
margin: 0 2px;
104+
padding: 6px;
105+
white-space: pre;
106+
}
107+
108+
pre code {
109+
border: none;
110+
margin: 0;
111+
padding: 0;
112+
white-space: pre;
113+
}
114+
}
115+
</style>

src/HtmlCard.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function __construct($component = null)
2424
$this->withMeta([
2525
'center' => false,
2626
'withoutCardStyles' => false,
27+
'withBasicStyles' => false,
2728
'content' => '',
2829
]);
2930
}
@@ -71,4 +72,10 @@ public function withoutCardStyles(bool $withoutStyles = true): static
7172
{
7273
return $this->withMeta(['withoutCardStyles' => $withoutStyles]);
7374
}
75+
76+
/** Whether to add basic styles for HTML content */
77+
public function withBasicStyles(bool $withBasicStyles = true): static
78+
{
79+
return $this->withMeta(['withBasicStyles' => $withBasicStyles]);
80+
}
7481
}

0 commit comments

Comments
 (0)