Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
daguilarm committed Apr 30, 2021
1 parent 6ba29ea commit 736d0df
Show file tree
Hide file tree
Showing 25 changed files with 1,188 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
risky: false
version: 8
preset: laravel
finder:
exclude:
- "modules"
- "node_modules"
- "storage"
- "vendor"
name: "*.php"
not-name:
- "*.blade.php"
- "_ide_helper.php"
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to `Livewire Combobox` will be documented in this file:

## 0.1.0 - 2021-04-28

- Initial commit
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

Please read and understand the contribution guide before creating an issue or pull request.

## Etiquette

This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.

Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.

It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.

## Viability

When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.

## Procedure

Before filing an issue:

- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.

Before submitting a pull request:

- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.

## Requirements

If the project maintainer has any additional requirements, you will find them listed here.

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

**Happy coding**!
64 changes: 64 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "daguilarm/livewire-combobox",
"description": "A Livewire select combobox for Laravel",
"keywords": [
"livewire",
"alpineJS",
"package",
"combobox",
"select",
"laravel",
"daguilarm"
],
"homepage": "https://github.com/daguilarm/livewire-combobox",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Damián Aguilar",
"email": "[email protected]",
"homepage": "https://daguilar.dev",
"role": "Developer"
}
],
"require": {
"php": "^8.0",
"livewire/livewire": "^2.3",
"mattlibera/livewire-flash": "^0.5.0",
"spatie/laravel-package-tools": "^1.6",
"symfony/http-kernel": "^5.0"
},
"require-dev": {
"calebporzio/sushi": "^2.2",
"nunomaduro/phpinsights": "dev-master",
"orchestra/testbench": "^6.13",
"phpunit/phpunit": "^9.4"
},
"autoload": {
"psr-4": {
"Daguilarm\\LivewireCombobox\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Daguilarm\\LivewireCombobox\\Tests\\": "tests"
}
},
"scripts": {
"psalm": "vendor/bin/psalm",
"test": "vendor/bin/phpunit --colors=always",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Daguilarm\\LivewireCombobox\\LivewireComboboxServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
10 changes: 10 additions & 0 deletions config/livewire-combobox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

return [
// /*
// * The package name
// */
// 'name' => 'Belich the Laravel database manager',
];
31 changes: 31 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Belich Tables Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
41 changes: 41 additions & 0 deletions resources/views/combobox.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div class="{{ $comboboxContainerClass ?? 'flex' }}">
@foreach ($elements as $element)
@if (Combobox::value($element, 'type') === 'select')
<div
class="{{ Combobox::value($element, 'fieldContainerCss') ?? 'px-2' }}"
id="field-container-for-{{ Combobox::value($element, 'uriKey') }}"
>
<label
id="{{ Combobox::value($element, 'uriKey') }}-label"
class="{{ Combobox::value($element, 'labelCss') ?? 'block w-full text-sm font-medium text-gray-600' }}"
for="{{ Combobox::value($element, 'uriKey') }}"
>
{{ Combobox::value($element, 'label') }}
</label>
<select
id="{{ Combobox::value($element, 'uriKey') }}"
name="{{ $element?->label ?? $element['uriKey'] }}"
class="{{ Combobox::value($element, 'fieldCss') ?? 'bg-white w-full relative border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 mt-1 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm' }}"
wire:model.defer="comboboxValues.{{ Combobox::value($element, 'uriKey') }}"
wire:change="$emit('dependOn', '{{ Combobox::value($element, 'uriKey') }}')"
>
{{-- Show or hide empty first element --}}
@unless(Combobox::value($element, 'firstRemove'))
<option></option>
@endunless

@foreach(Combobox::value($element, 'options') as $key => $value)
<option
value="{{ $value ?? Combobox::value($element, 'defaultValue') }}"
@if(is_array($element) && $element['defaultValue'] == $value)
selected
@endif
>
{{ $key }}
</option>
@endforeach
</select>
</div>
@endif
@endforeach
</div>
31 changes: 31 additions & 0 deletions src/Components/Combobox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Daguilarm\LivewireCombobox\Components;

/**
* Class Combobox.
*/
final class Combobox
{
/**
* Get value from element.
*
* @param int | bool | float | string | null $value
*
* @return array | bool | int | float | string | null
*/
public function value(object | array $element, $value)
{
if(is_array($element)) {
return isset($element[$value]) ? $element[$value] : null;
}

if(is_object($element)) {
return $element?->{$value} ?? null;
}

return null;
}
}
Loading

0 comments on commit 736d0df

Please sign in to comment.