Skip to content

Commit 0882447

Browse files
committed
#5 #11 Add a hack to use full-width while keeping original card order
1 parent d4d29d6 commit 0882447

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function cards()
3939
- `->view('path.to.view', [])`: Specify blade view file and optionally pass an array of data to view.
4040
- Styling
4141
- `->center(false)`: Center card's content. `false` by default.
42-
- `->withoutCardStyles(true)`: Whether to use standard Nova Card styles for a card (background, padding, etc). `false` by default.
42+
- `->withoutCardStyles(true)`: Whether to use standard Nova Card styles for a card (background, padding, etc). `false` by default.
43+
- `->forceFullWidth(true)`: Force the card to be full width. A fix for [nova cards order](https://github.com/laravel/nova-issues/issues/1895).
4344

4445

4546
## Why this package?

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=f3dee4c8ebf64203b09e"
2+
"/js/card.js": "/js/card.js?id=b29fdbc6a04f01db20f0"
33
}

resources/js/components/Card.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
2727
return classes;
2828
},
29-
}
29+
},
30+
mounted() {
31+
if (this.card.forceFullWidth) {
32+
this.$parent.$el.classList.remove('w-5/6');
33+
this.$parent.$el.classList.add('w-full');
34+
}
35+
},
3036
}
3137
</script>
3238

src/HtmlCard.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct($component = null)
2727
$this->withMeta([
2828
'center' => false,
2929
'withoutCardStyles' => false,
30+
'forceFullWidth' => false,
3031
'content' => '',
3132
]);
3233
}
@@ -90,6 +91,22 @@ public function center(bool $centerContent = true)
9091
return $this->withMeta(['center' => $centerContent]);
9192
}
9293

94+
/**
95+
* Force Nova to apply full width for a card.
96+
* Nova has undocumented feature to auto-order cards based on width and put
97+
* full-width cards at the bottom. If you want to display full-width cards
98+
* not at the end, you should use with=1/3 or 2/3 and this method.
99+
* @see https://github.com/laravel/nova-issues/issues/1895#issuecomment-543684472
100+
*
101+
* @param bool $forceFullWidth
102+
*
103+
* @return HtmlCard
104+
*/
105+
public function forceFullWidth(bool $forceFullWidth = true)
106+
{
107+
return $this->withMeta(['forceFullWidth' => $forceFullWidth]);
108+
}
109+
93110
/**
94111
* Whether to use standard Nova Card styles for a card (background, padding, etc)
95112
*

0 commit comments

Comments
 (0)