Fields

Code

More information about the field can be found in the package repository.

Installation

Before using, you need to install the package:

composer require moonshine/ace
composer require moonshine/ace

Basics

Inherits Textarea.

* has the same capabilities.

The Code field is an extension of Textarea with a visual layout for editing code.

use MoonShine\Ace\Fields\Code; Code::make('Code')
use MoonShine\Ace\Fields\Code;
 
Code::make('Code')

fields_code

The field is based on the Ace library.

Default Config

To change the default settings, you need to publish the configuration file:

php artisan vendor:publish --tag="moonshine-ace-config"
php artisan vendor:publish --tag="moonshine-ace-config"

You can also add additional parameters to the configuration file that will apply to all Code fields.

'options' => [ 'language' => 'javascript', 'options' => [ 'useSoftTabs' => true, 'navigateWithinSoftTabs' => true, ], 'themes' => [ 'light' => 'chrome', 'dark' => 'cobalt' ], ],
'options' => [
'language' => 'javascript',
'options' => [
'useSoftTabs' => true,
'navigateWithinSoftTabs' => true,
],
'themes' => [
'light' => 'chrome',
'dark' => 'cobalt'
],
],

Language

By default, the layout for PHP is used, but you can change it for another programming language using the language() method.

language(string $language)
language(string $language)

Supported languages: HTML, XML, CSS, PHP, JavaScript, and many others.

Code::make('Code') ->language('js')
Code::make('Code')
->language('js')

Themes

To change themes, use the themes() method.

themes(string $light = null, string $dark = null)
themes(string $light = null, string $dark = null)
Code::make('Code') ->themes('chrome', 'cobalt');
Code::make('Code')
->themes('chrome', 'cobalt');

Options

The addOption() method allows you to add additional options for the field.

addOption(string $name, string|int|float|bool $value)
addOption(string $name, string|int|float|bool $value)
Code::make('Code') ->addOption('showGutter', false)
Code::make('Code')
->addOption('showGutter', false)