All Projects → inspheric → nova-url-field

inspheric / nova-url-field

Licence: MIT license
A URL input and link field for Laravel Nova

Programming Languages

PHP
23972 projects - #3 most used programming language
Vue
7211 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nova-url-field

nova-hidden-field
A Laravel Nova Hidden field.
Stars: ✭ 32 (-66.67%)
Mutual labels:  nova, laravel-nova, laravel-nova-field
nova-qrcode-field
A Laravel Nova field to generate QR Code
Stars: ✭ 28 (-70.83%)
Mutual labels:  laravel-package, nova, laravel-nova
Laravel Nova Excel
🚀 Supercharged Excel exports for Laravel Nova Resources
Stars: ✭ 259 (+169.79%)
Mutual labels:  laravel-package, nova
Nova Indicator Field
A colour-coded indicator field for Laravel Nova
Stars: ✭ 108 (+12.5%)
Mutual labels:  laravel-package, nova
nova-json-wrapper
Allows you to group Nova fields and merge their output into a single JSON column
Stars: ✭ 14 (-85.42%)
Mutual labels:  nova, laravel-nova-field
laravel-nova-visual-composer
Visual Composer for Laravel Nova
Stars: ✭ 15 (-84.37%)
Mutual labels:  nova, laravel-nova
Nova-Dark-Theme
A dark theme for Laravel Nova
Stars: ✭ 72 (-25%)
Mutual labels:  laravel-package, nova
nova-table-field
Table field for Laravel Nova
Stars: ✭ 29 (-69.79%)
Mutual labels:  laravel-nova, laravel-nova-field
nova-horizon-stats
Nova cards for Laravel applications that use Laravel Horizon
Stars: ✭ 31 (-67.71%)
Mutual labels:  nova, laravel-nova
nova-unlayer-field
🦜 Drag’n’drop email builder for Laravel Nova that uses Adds a Laravel Nova field for Unlayer service under the hood.
Stars: ✭ 27 (-71.87%)
Mutual labels:  nova, laravel-nova-field
nova-inspire
The best way to connect with your customers is by reaching out and inspiring them. ~ Me
Stars: ✭ 14 (-85.42%)
Mutual labels:  nova, laravel-nova
nova-sluggable
Slug field for Laravel Nova
Stars: ✭ 40 (-58.33%)
Mutual labels:  nova, laravel-nova
nova-grouped-field
Combine multiple Nova fields as one field output
Stars: ✭ 43 (-55.21%)
Mutual labels:  laravel-nova, laravel-nova-field
nova-rating-field
A Star rating field to use in your Laravel Nova apps.
Stars: ✭ 42 (-56.25%)
Mutual labels:  laravel-package, laravel-nova
nova-inline-morph-to
A Laravel Nova field for displaying morphTo relationship inline.
Stars: ✭ 32 (-66.67%)
Mutual labels:  nova, laravel-nova-field
nova-system-resources
Display the system usage in Laravel-Nova
Stars: ✭ 30 (-68.75%)
Mutual labels:  nova, laravel-nova
laravel-nova-order-nestedset-field
Laravel Nova field that make your resources orderable
Stars: ✭ 21 (-78.12%)
Mutual labels:  nova, laravel-nova
nova-html
This field allows you display custom HTML in Laravel Nova, be it a link, an image or any other piece of proper html.
Stars: ✭ 13 (-86.46%)
Mutual labels:  laravel-nova
cj-temporal-models
No description or website provided.
Stars: ✭ 29 (-69.79%)
Mutual labels:  laravel-package
nova-custom-dashboard-card
A Laravel Nova dashboard card that allows you to build custom dashboards.
Stars: ✭ 84 (-12.5%)
Mutual labels:  nova

Laravel Nova URL Field

A URL input and link field for Laravel Nova

Latest Version on Packagist Total Downloads

Installation

Install the package into a Laravel app that uses Nova with Composer:

composer require inspheric/nova-url-field

Usage

Add the field to your resource in the fields method:

use Inspheric\Fields\Url;

Url::make('Homepage')
    ->rules('url', /* ... */),

The field extends the Laravel\Nova\Fields\Text field, so all the usual methods are available.

Supports readonly, placeholder and overriding the default type="url" if you prefer not to have the validation in the browser. This is from the standard Nova Text field so is not documented here.

It is recommended that you include the standard url and/or active_url validation rules, as they are not automatically added.

Options

Terminology: label, title, value

The terms "label", "title" and "value" are used to describe the following options. They should be understood within the generated HTML as follows:

<a href="{{ $value }}" title="{{ $title }}">{{ $label }}</a>

Label

Make the field display with a label instead of the URL value itself on the detail or index pages:

Url::make('Homepage')
    ->label('External Link'),

You can, of course use the Laravel trans() or __() functions to translate the label.

The label is only displayed if the link is clickable, otherwise the URL value is displayed.

Label Using

Make the field display with a label using a callback:

Url::make('Homepage')
    ->labelUsing(function($value, $resource) {
        return $this->title;
    }),

The arguments $value and $resource are passed in the same way as the callback for resolveUsing(), but are optional.

HTML Label

If you would like to use custom HTML for the label, remember to also use the asHtml() option.

Url::make('Homepage')
    ->label('<strong>External</strong> Link')
    ->asHtml(),

Domain Label

A shortcut method to display the domain part only of the URL (i.e. without https?://www.) as the label:

Url::make('Homepage')
    ->domainLabel(),

For example, the label for the field value https://www.example.com/path?query=value&another=true#fragment would display simply as example.com.

This is resolved after the displayUsing() callback if you have one, so if you modify the display of the URL in some way, the modified value will be passed to this label.

Name Label

A shortcut method to display the name of the field as the label:

Url::make('Homepage')
    ->nameLabel(),

The label would be displayed as Homepage.

Title

Set the link's title attribute, which will be displayed when the mouse hovers over it:

Url::make('Homepage')
    ->title('Link title'),

You can, of course use the Laravel trans() or __() functions to translate the label. If no custom title is set, the full URL value will be used.

The title is only used if the link is clickable.

Title Using

Set the title using a callback:

Url::make('Homepage')
    ->titleUsing(function($value, $resource) {
        return $this->title;
    }),

Clickable

Make the field display as a link on the detail page:

Url::make('Homepage')
    ->clickable(bool $clickable = true),

Clickable on Index

Make the field display as a link on the index page:

Url::make('Homepage')
    ->clickableOnIndex(bool $clickable = true),

Always Clickable

Combination of the two functions above for simplicity:

Url::make('Homepage')
    ->alwaysClickable(bool $clickable = true),

Open in Same Tab

By default, the clickable link will open in a new tab (using target="_blank"). You can modify this behaviour so that the link opens in the same tab:

Url::make('Homepage')
    ->sameTab(bool $sameTab = true),

rel=noopener and rel=noreferrer

By default, a clickable link will open in a new tab and will have the rel=noopener attribute set*. If you use sameTab() as above, rel=noopener will be unset.

To override the default behaviour, you can choose to set or unset rel=noopener and/or rel=noreferrer with the following methods:

Url::make('Homepage')
    ->noopener(bool $noopener = true),

Url::make('Homepage')
    ->noreferrer(bool $noreferrer = true),

If you use both sameTab() and noopener() on the same field, ensure that noopener() comes after sameTab() or the two settings will cancel each other out.

* See this article for an explanation.

Custom HTML

If you do not wish the link to be displayed with the default icon and text, you can set custom HTML which will replace the entire contents of the default template:

Url::make('Homepage')
    ->customHtml('<span class="my-class">Click here!</span>'),

If the link is clickable, this content will be wrapped in an unstyled <a> tag which implements all of the other options you have specified, such as sameTab, title etc.

If you do want the link to appear as link-styled text, you can add the classes dim text-primary within the HTML you specify.

Important! It is your responsibility to escape or sanitize any user-provided data before displaying it as raw HTML. This package does not do that for you.

Custom HTML Using

Set the custom HTML using a callback:

Url::make('Homepage')
    ->customHtmlUsing(function($value, $resource, $label) {
        return view('partials.link_text', [
            'url'   => $value,
            'label' => $label,
        ])->render();
    }),

Note that the callback has a third argument $label, which will contain the appropriate label based on which of the label(), labelUsing(), nameLabel(), domainLabel() etc. options you have set on the field.

Remember that if the link is clickable, the custom HTML you specify is already wrapped in an <a href=""> tag, so you should not include an <a> tag in your own custom HTML.

Appearance

Index (default)

index-field

The field is displayed as a plain <span> element.

Index (clickable)

index-field-clickable

The field is displayed as an <a href="..."> element with an icon.

Index (clickable with label)

index-field-clickable-label

The field is displayed as an <a href="..."> element with an icon and a custom label.

Detail (default)

detail-field

The field is displayed as a plain <span> element.

Detail (clickable)

detail-field-clickable

The field is displayed as an <a href="..."> element with an icon.

Detail (clickable with label)

detail-field-clickable-label

The field is displayed as an <a href="..."> element with an icon and a custom label.

Form

form-field

The field is displayed as an <input type="url"> element.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].