Skip to content

Commit

Permalink
Merge pull request #488 from DissNik/2.0
Browse files Browse the repository at this point in the history
change Number field
  • Loading branch information
DissNik authored Jun 5, 2024
2 parents f795a10 + ed03553 commit 73847a0
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 63 deletions.
2 changes: 1 addition & 1 deletion config/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'Fields:table-cells' => [
['slug' => 'fields-index', 'label' => 'Basics'],
// Text
'Text:_divider_',
'Input:_divider_',
['slug' => 'fields-text', 'label' => 'Text'],
['slug' => 'fields-hidden', 'label' => 'Hidden'],
['slug' => 'fields-id', 'label' => 'ID'],
Expand Down
2 changes: 1 addition & 1 deletion resources/views/pages/en/fields/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ function(Fields $fields, ?string $value, Field $field, array $values)
</x-ul>

<x-moonshine::alert type="default" icon="heroicons.information-circle">
Fields that support reactivity: <code>Text</code>, <code>Checkbox</code>, <code>Select</code>
Fields that support reactivity: <code>Text</code>, <code>Number</code>, <code>Checkbox</code>, <code>Select</code>
and their successors.
</x-moonshine::alert>

Expand Down
42 changes: 41 additions & 1 deletion resources/views/pages/en/fields/number.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
:sectionMenu="[
'Sections' => [
['url' => '#make', 'label' => 'Make'],
['url' => '#default', 'label' => 'Default value'],
['url' => '#readonly', 'label' => 'Only for reading'],
['url' => '#placeholder', 'label' => 'Placeholder'],
['url' => '#attributes', 'label' => 'Attributes'],
['url' => '#stars', 'label' => 'Stars'],
['url' => '#buttons', 'label' => '+/- buttons'],
['url' => '#update-on-preview', 'label' => 'Editing in preview'],
]
]"
>
Expand Down Expand Up @@ -36,10 +40,44 @@ public function fields(): array
//...
</x-code>

<x-sub-title id="default">Default value</x-sub-title>

<x-p>
You can use the <code>default()</code> method if you need to specify a default value for a field.
</x-p>

<x-code language="php">
default(mixed $default)
</x-code>

<x-code language="php">
use MoonShine\Fields\Number;

//...

public function fields(): array
{
return [
Number::make('Title')
->default(2) // [tl! focus]
];
}

//...
</x-code>

@include('pages.en.fields.shared.readonly', ['field' => 'Number'])

@include('pages.en.fields.shared.placeholder', [
'field' => 'Number',
'label' => 'Rating',
'placeholder' => 'Product rating'
])

<x-sub-title id="attributes">Attributes</x-sub-title>

<x-p>
The <em>Number</em> field has additional attributes (besides the standard attributes of the <em>Text</em> field),
The <em>Number</em> field has additional attributes,
which can be set through the appropriate methods.
</x-p>

Expand Down Expand Up @@ -147,4 +185,6 @@ public function fields(): array
<x-image theme="light" src="{{ asset('screenshots/number_buttons.png') }}"></x-image>
<x-image theme="dark" src="{{ asset('screenshots/number_buttons_dark.png') }}"></x-image>

@include('pages.en.fields.shared.update_on_preview', ['field' => 'Number'])

</x-page>
8 changes: 6 additions & 2 deletions resources/views/pages/en/fields/shared/placeholder.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@props([
'label' => $field === 'BelongsToMany' ? 'Countries' : 'Country',
'placeholder' => $field === 'BelongsToMany' ? 'Countries' : 'Country',
])
<x-sub-title id="placeholder">Placeholder</x-sub-title>

<x-p>
Expand All @@ -16,9 +20,9 @@
public function fields(): array
{
return [
{{ $field }}::make({!! $field === 'BelongsToMany' ? "'Countries'" : "'Country'" !!}, {!! $field === 'BelongsToMany' ? "'countries'" : "'country'" !!})
{{ $field }}::make('{{ $label }}', '{{ str($label)->snake() }}')
->nullable()
->placeholder('{!! $field === 'BelongsToMany' ? 'Countries' : 'Country' !!}') // [tl! focus]
->placeholder('{{ $placeholder }}') // [tl! focus]
];
}

Expand Down
25 changes: 25 additions & 0 deletions resources/views/pages/en/fields/shared/readonly.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<x-sub-title id="readonly">Only for reading</x-sub-title>

<x-p>
If the field is read-only, then you must use the <code>readonly()</code> method.
</x-p>

<x-code language="php">
readonly(Closure|bool|null $condition = null)
</x-code>

<x-code language="php">
use MoonShine\Fields\{{ $field }};

//...

public function fields(): array
{
return [
{{ $field }}::make('Title')
->readonly() // [tl! focus]
];
}

//...
</x-code>
26 changes: 1 addition & 25 deletions resources/views/pages/en/fields/text.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,7 @@ public function fields(): array
//...
</x-code>

<x-sub-title id="readonly">Only for reading</x-sub-title>

<x-p>
If the field is read-only, then you must use the <code>readonly()</code> method.
</x-p>

<x-code language="php">
readonly(Closure|bool|null $condition = null)
</x-code>

<x-code language="php">
use MoonShine\Fields\Text;

//...

public function fields(): array
{
return [
Text::make('Title')
->readonly() // [tl! focus]
];
}

//...
</x-code>
@include('pages.en.fields.shared.readonly', ['field' => 'Text']))

<x-sub-title id="mask">Mask</x-sub-title>

Expand Down
2 changes: 1 addition & 1 deletion resources/views/pages/ru/fields/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ function(Fields $fields, ?string $value, Field $field, array $values)
</x-ul>

<x-moonshine::alert type="default" icon="heroicons.information-circle">
Поля поддерживающие реактивность: <code>Text</code>, <code>Checkbox</code>, <code>Select</code>
Поля поддерживающие реактивность: <code>Text</code>, <code>Number</code>, <code>Checkbox</code>, <code>Select</code>
и их наследующие.
</x-moonshine::alert>

Expand Down
46 changes: 41 additions & 5 deletions resources/views/pages/ru/fields/number.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
:sectionMenu="[
'Разделы' => [
['url' => '#make', 'label' => 'Make'],
['url' => '#default', 'label' => 'Значение по умолчанию'],
['url' => '#readonly', 'label' => 'Только для чтения'],
['url' => '#placeholder', 'label' => 'Placeholder'],
['url' => '#attributes', 'label' => 'Атрибуты'],
['url' => '#stars', 'label' => 'Stars'],
['url' => '#buttons', 'label' => 'Кнопки +/-'],
['url' => '#update-on-preview', 'label' => 'Редактирование в preview'],
]
]"
>

<x-extendby :href="to_page('fields-text')">
Text
</x-extendby>

<x-sub-title id="make">Make</x-sub-title>

<x-p>
Expand All @@ -36,10 +36,44 @@ public function fields(): array
//...
</x-code>

<x-sub-title id="default">Значение по умолчанию</x-sub-title>

<x-p>
Можно воспользоваться методом <code>default()</code>, если необходимо указать значение по умолчанию для поля.
</x-p>

<x-code language="php">
default(mixed $default)
</x-code>

<x-code language="php">
use MoonShine\Fields\Number;

//...

public function fields(): array
{
return [
Number::make('Title')
->default(2) // [tl! focus]
];
}

//...
</x-code>

@include('pages.ru.fields.shared.readonly', ['field' => 'Number'])

@include('pages.ru.fields.shared.placeholder', [
'field' => 'Number',
'label' => 'Rating',
'placeholder' => 'Product rating'
])

<x-sub-title id="attributes">Атрибуты</x-sub-title>

<x-p>
Поле <em>Number</em> имеет дополнительные атрибуты (кроме стандартных атрибутов поля <em>Text</em>),
Поле <em>Number</em> имеет дополнительные атрибуты,
которые можно задать через соответствующие методы.
</x-p>

Expand Down Expand Up @@ -147,4 +181,6 @@ public function fields(): array
<x-image theme="light" src="{{ asset('screenshots/number_buttons.png') }}"></x-image>
<x-image theme="dark" src="{{ asset('screenshots/number_buttons_dark.png') }}"></x-image>

@include('pages.ru.fields.shared.update_on_preview', ['field' => 'Number'])

</x-page>
8 changes: 6 additions & 2 deletions resources/views/pages/ru/fields/shared/placeholder.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@props([
'label' => $field === 'BelongsToMany' ? 'Countries' : 'Country',
'placeholder' => $field === 'BelongsToMany' ? 'Countries' : 'Country',
])
<x-sub-title id="placeholder">Placeholder</x-sub-title>

<x-p>
Expand All @@ -16,9 +20,9 @@
public function fields(): array
{
return [
{{ $field }}::make({!! $field === 'BelongsToMany' ? "'Countries'" : "'Country'" !!}, {!! $field === 'BelongsToMany' ? "'countries'" : "'country'" !!})
{{ $field }}::make('{{ $label }}', '{{ str($label)->snake() }}')
->nullable()
->placeholder('{!! $field === 'BelongsToMany' ? 'Countries' : 'Country' !!}') // [tl! focus]
->placeholder('{{ $placeholder }}') // [tl! focus]
];
}

Expand Down
25 changes: 25 additions & 0 deletions resources/views/pages/ru/fields/shared/readonly.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<x-sub-title id="readonly">Только для чтения</x-sub-title>

<x-p>
Если поле доступно только для чтения, то необходимо воспользоваться методом <code>readonly()</code>.
</x-p>

<x-code language="php">
readonly(Closure|bool|null $condition = null)
</x-code>

<x-code language="php">
use MoonShine\Fields\{{ $field }};

//...

public function fields(): array
{
return [
{{ $field }}::make('Title')
->readonly() // [tl! focus]
];
}

//...
</x-code>
26 changes: 1 addition & 25 deletions resources/views/pages/ru/fields/text.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,7 @@ public function fields(): array
//...
</x-code>

<x-sub-title id="readonly">Только для чтения</x-sub-title>

<x-p>
Если поле доступно только для чтения, то необходимо воспользоваться методом <code>readonly()</code>.
</x-p>

<x-code language="php">
readonly(Closure|bool|null $condition = null)
</x-code>

<x-code language="php">
use MoonShine\Fields\Text;

//...

public function fields(): array
{
return [
Text::make('Title')
->readonly() // [tl! focus]
];
}

//...
</x-code>
@include('pages.ru.fields.shared.readonly', ['field' => 'Text']))

<x-sub-title id="mask">Маска</x-sub-title>

Expand Down

0 comments on commit 73847a0

Please sign in to comment.