Skip to content

Commit

Permalink
Merge pull request #3 from mdpoulter/icon-support
Browse files Browse the repository at this point in the history
Add icon support
  • Loading branch information
oleghalin authored Nov 5, 2019
2 parents 4161008 + 5bd7e9e commit ba2b1ed
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,20 @@ Link::make('Charge Id', 'stripe_id')
->text("Go To Stripe")
```

#### Open link in blank window
### Show icon instead of text
Replaces text with an icon on the index view. For this needs you can use `icon()` function

Example:
```
Link::make('Charge Id', 'stripe_id')
->url(function () {
return "https://dashboard.stripe.com/payments/{$this->stripe_id}";
})
->text("Go To Stripe")
->icon()
```

### Open link in blank window
For this needs you can use `blank()` function.

Example:
Expand All @@ -56,7 +69,7 @@ Link::make('Charge Id', 'stripe_id')
->blank()
```

#### Add additional classes to `<a>`
### Add additional classes to `<a>`
For this needs you can use `classes()` function (accept `Callable` or `text`).

Example:
Expand All @@ -68,5 +81,5 @@ Link::make('Charge Id', 'stripe_id')
```


### TODO
## TODO
- [ ] Cover field with tests
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
],
"license": "MIT",
"require": {
"php": ">=7.1.0"
"php": ">=7.1.0",
"laravel/nova": "^2.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions resources/js/components/Icons/ExternalLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template functional>
<path d="M19 6.41L8.7 16.71a1 1 0 1 1-1.4-1.42L17.58 5H14a1 1 0 0 1 0-2h6a1 1 0 0 1 1 1v6a1 1 0 0 1-2 0V6.41zM17 14a1 1 0 0 1 2 0v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7c0-1.1.9-2 2-2h5a1 1 0 0 1 0 2H5v12h12v-5z" />
</template>
13 changes: 8 additions & 5 deletions resources/js/components/IndexField.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<template>
<a v-if="hasValue" :target="field.blank ? field.blank : '_self'" :class="field.classes ? field.classes : defaultClasses"
:href="field.href">
{{ field.text ? field.text : field.value }}
</a>
<p v-else>&mdash;</p>
<div :class="`text-${field.textAlign}`">
<a v-if="hasValue" :target="field.blank ? field.blank : '_self'" :class="field.classes ? field.classes : defaultClasses"
:href="field.href">
<span v-if="field.icon"><icon :type="field.icon" height="24" view-box="0 0 24 24" width="24"/></span>
<span v-else>{{ field.text ? field.text : field.value }}</span>
</a>
<p v-else>&mdash;</p>
</div>
</template>

<script>
Expand Down
1 change: 1 addition & 0 deletions resources/js/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Nova.booting((Vue, router, store) => {
Vue.component('index-nova-link-field', require('./components/IndexField'))
Vue.component('detail-nova-link-field', require('./components/DetailField'))
Vue.component('form-nova-link-field', require('./components/FormField'))
Vue.component('icon-external-link', require('./components/Icons/ExternalLink'))
})
15 changes: 15 additions & 0 deletions src/NovaLinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public function text($text)
return $this;
}

/**
* @param string $icon
* @return $this
*/
public function icon($icon = 'external-link')
{
$this->withMeta([
'icon' => $icon,
]);

$this->textAlign('center');

return $this;
}

/**
* @return array
*/
Expand Down

0 comments on commit ba2b1ed

Please sign in to comment.