Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rawilk committed Sep 16, 2020
2 parents b4cdd37 + df2bdb4 commit 636188e
Show file tree
Hide file tree
Showing 10 changed files with 1,778 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ return [
'view' => 'form-components::components.form-error',
],

'timezone-select' => [
'class' => Components\Inputs\TimezoneSelect::class,
'view' => 'form-components::components.inputs.timezone-select',
],

],

/*
Expand All @@ -134,6 +139,33 @@ return [
*/
'prefix' => '',

/*
|--------------------------------------------------------------------------
| Enable Timezone Select
|--------------------------------------------------------------------------
|
| If you don't plan on using a timezone select in your app, you can disable
| it here. This will prevent the use of app('fc-timezone'). You should also
| remove the "timezone-select" from the registered components in the config
| as well.
|
*/
'enable_timezone' => true,

/*
|--------------------------------------------------------------------------
| Default Timezone Subset
|--------------------------------------------------------------------------
|
| You may not always need the full list of timezones to choose from,
| so you may define a subset of regions to pull from instead. Set
| the value to `false` to use all regions.
|
| Example: [\Rawilk\FormComponents\Support\TimezoneRegion::AMERICA]
|
*/
'timezone_subset' => false,

];
```

Expand Down
32 changes: 32 additions & 0 deletions config/form-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
'view' => 'form-components::components.form-error',
],

'timezone-select' => [
'class' => Components\Inputs\TimezoneSelect::class,
'view' => 'form-components::components.inputs.timezone-select',
],

],

/*
Expand All @@ -106,4 +111,31 @@
*/
'prefix' => '',

/*
|--------------------------------------------------------------------------
| Enable Timezone Select
|--------------------------------------------------------------------------
|
| If you don't plan on using a timezone select in your app, you can disable
| it here. This will prevent the use of app('fc-timezone'). You should also
| remove the "timezone-select" from the registered components in the config
| as well.
|
*/
'enable_timezone' => true,

/*
|--------------------------------------------------------------------------
| Default Timezone Subset
|--------------------------------------------------------------------------
|
| You may not always need the full list of timezones to choose from,
| so you may define a subset of regions to pull from instead. Set
| the value to `false` to use all regions.
|
| Example: [\Rawilk\FormComponents\Support\TimezoneRegion::AMERICA]
|
*/
'timezone_subset' => false,

];
651 changes: 651 additions & 0 deletions docs/components/timezone-select.md

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ return [
'view' => 'form-components::components.form-error',
],

'timezone-select' => [
'class' => Components\Inputs\TimezoneSelect::class,
'view' => 'form-components::components.inputs.timezone-select',
],

],

/*
Expand All @@ -128,6 +133,33 @@ return [
*/
'prefix' => '',

/*
|--------------------------------------------------------------------------
| Enable Timezone Select
|--------------------------------------------------------------------------
|
| If you don't plan on using a timezone select in your app, you can disable
| it here. This will prevent the use of app('fc-timezone'). You should also
| remove the "timezone-select" from the registered components in the config
| as well.
|
*/
'enable_timezone' => true,

/*
|--------------------------------------------------------------------------
| Default Timezone Subset
|--------------------------------------------------------------------------
|
| You may not always need the full list of timezones to choose from,
| so you may define a subset of regions to pull from instead. Set
| the value to `false` to use all regions.
|
| Example: [\Rawilk\FormComponents\Support\TimezoneRegion::AMERICA]
|
*/
'timezone_subset' => false,

];
```

Expand Down
30 changes: 30 additions & 0 deletions resources/views/components/inputs/timezone-select.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="form-text-container {{ $maxWidth }}">
@include('form-components::partials.leading-addons')

<select name="{{ $name }}"
id="{{ $id }}"
@if ($multiple) multiple @endif

@if ($hasErrorsAndShow($name))
aria-invalid="true"

@if (! $attributes->offsetExists('aria-describedby'))
aria-describedby="{{ $id }}-error"
@endif
@endif

{{ $attributes->merge(['class' => $inputClass()]) }}
>
{{ $slot }}

@foreach (app('fc-timezone')->only($only)->all() as $region => $regionTimezones)
<optgroup label="{{ $region }}">
@foreach ($regionTimezones as $key => $display)
<option value="{{ $key }}"@if ($isSelected($key)) selected @endif>{{ $display }}</option>
@endforeach
</optgroup>
@endforeach
</select>

@include('form-components::partials.trailing-addons')
</div>
54 changes: 54 additions & 0 deletions src/Components/Inputs/TimezoneSelect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Rawilk\FormComponents\Components\Inputs;

class TimezoneSelect extends Select
{
/** @var string */
public $selectedKey;

public bool $multiple;

/** @var string */
public $maxWidth;

public $only;

public function __construct(
string $name = '',
string $id = null,
$value = null,
bool $multiple = false,
string $maxWidth = null,
bool $showErrors = true,
$leadingAddon = false,
$inlineAddon = false,
$inlineAddonPadding = self::DEFAULT_INLINE_ADDON_PADDING,
$leadingIcon = false,
$trailingAddon = false,
$trailingAddonPadding = self::DEFAULT_TRAILING_ADDON_PADDING,
$trailingIcon = false,
$only = null
) {
parent::__construct(
$name,
$id,
[],
$value,
$multiple,
$maxWidth,
$showErrors,
$leadingAddon,
$inlineAddon,
$inlineAddonPadding,
$leadingIcon,
$trailingAddon,
$trailingAddonPadding,
$trailingIcon
);

$this->only = is_null($only) ? config('form-components.timezone_subset', false) : $only;
}
}
10 changes: 10 additions & 0 deletions src/FormComponentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Compilers\BladeCompiler;
use Rawilk\FormComponents\Console\PublishCommand;
use Rawilk\FormComponents\Support\Timezone;

class FormComponentsServiceProvider extends ServiceProvider
{
Expand All @@ -27,6 +28,8 @@ public function boot(): void
public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/../config/form-components.php', 'form-components');

$this->registerTimezone();
}

private function bootBladeComponents(): void
Expand Down Expand Up @@ -55,4 +58,11 @@ private function bootResources(): void
{
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'form-components');
}

private function registerTimezone(): void
{
if (config('form-components.enable_timezone')) {
$this->app->singleton('fc-timezone', fn () => new Timezone);
}
}
}
45 changes: 45 additions & 0 deletions src/Support/TimeZoneRegion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Rawilk\FormComponents\Support;

final class TimeZoneRegion
{
/**
* A "general" timezone region.
*
* @var string
*/
public const GENERAL = 'General';

/** @var string */
public const AFRICA = 'Africa';

/** @var string */
public const AMERICA = 'America';

/** @var string */
public const ANTARCTICA = 'Antarctica';

/** @var string */
public const ARCTIC = 'Arctic';

/** @var string */
public const ASIA = 'Asia';

/** @var string */
public const ATLANTIC = 'Atlantic';

/** @var string */
public const AUSTRALIA = 'Australia';

/** @var string */
public const EUROPE = 'Europe';

/** @var string */
public const INDIAN = 'Indian';

/** @var string */
public const PACIFIC = 'Pacific';
}
Loading

0 comments on commit 636188e

Please sign in to comment.