Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrocfe committed Apr 25, 2023
2 parents 6a668f4 + 7fd95b0 commit f9cc6ba
Show file tree
Hide file tree
Showing 27 changed files with 456 additions and 426 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a
url: https://github.com/leandrocfe/filament-ptbr-form-fields/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas
url: https://github.com/leandrocfe/filament-ptbr-form-fields/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue
url: https://github.com/:vendor_name/:package_name/security/policy
url: https://github.com/leandrocfe/filament-ptbr-form-fields/security/policy
about: Learn how to notify us for sensitive bugs
31 changes: 0 additions & 31 deletions .github/workflows/update-changelog.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Changelog

All notable changes to `:package_name` will be documented in this file.
All notable changes to `filament-ptbr-form-fields` will be documented in this file.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) :vendor_name <author@domain.com>
Copyright (c) leandrocfe <leandrocfe@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
181 changes: 139 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,167 @@
# :package_description
# Brazilian pt-BR form fields.

[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
<!--delete-->
---
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
This package provides custom form fields for [Filament](https://filamentphp.com/) (**>=v2.17.28**) that are commonly used in Brazilian web applications, such as CPF/CNPJ validation, phone number formatting, money with currency symbol, and CEP integration with [ViaCep](https://viacep.com.br).

1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton.
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files.
3. Have fun creating your package.
4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
---
<!--/delete-->
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
This package uses [LaravelLegends/pt-br-validator](https://github.com/LaravelLegends/pt-br-validator) to validate Brazilian Portuguese fields.

## Support us
![image demo](https://raw.githubusercontent.com/leandrocfe/filament-ptbr-form-fields/develop/screenshots/v1-example.png)

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name)
## Installation

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
You can install the package via Composer:

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
```bash
composer require leandrocfe/filament-ptbr-form-fields
```

## Installation
## Usage

You can install the package via composer:
### CPF / CNPJ

```bash
composer require :vendor_slug/:package_slug
To create a dynamic input that accepts either CPF or CNPJ, use:

```php
use Leandrocfe\FilamentPtbrFormFields\PtbrCpfCnpj;
PtbrCpfCnpj::make('cpf_or_cnpj')
```

You can publish and run the migrations with:
You can also add validation to this field by chaining the rule() method:

```bash
php artisan vendor:publish --tag=":package_slug-migrations"
php artisan migrate
```php
PtbrCpfCnpj::make('cpf_or_cnpj')
->rule('cpf_ou_cnpj')
```

You can publish the config file with:
If you want to create an input that only accepts CPF or only accepts CNPJ, use:

```bash
php artisan vendor:publish --tag=":package_slug-config"
```php
//CPF
PtbrCpfCnpj::make('cpf')
->cpf()
```

```php
//CNPJ
PtbrCpfCnpj::make('cnpj')
->cnpj()
```

This is the contents of the published config file:
You can also add validation to these fields as well:

```php
return [
];
//CPF with validation
PtbrCpfCnpj::make('cpf')
->cpf()
->rule('cpf')
```

Optionally, you can publish the views using
```php
//CNPJ with validation
PtbrCpfCnpj::make('cnpj')
->cnpj()
->rule('cnpj')
```

```bash
php artisan vendor:publish --tag=":package_slug-views"
If you want to use a custom mask for the input, use the cpf() or cnpj() method with a string argument representing the desired mask:

```php
PtbrCpfCnpj::make('cpf')
->cpf('999999999-99')
```

## Usage
```php
PtbrCpfCnpj::make('cnpj')
->cnpj('99999999/9999-57')
```

### Phone number

To create a dynamic input that formats phone numbers with DDD, use:

```php
$variable = new VendorName\Skeleton();
echo $variable->echoPhrase('Hello, VendorName!');
use Leandrocfe\FilamentPtbrFormFields\PtbrPhone;
PtbrPhone::make('phone_number')
```

If you want to use a custom phone number format, use the format() method with a string argument representing the desired format:

```php
PtbrPhone::make('phone_number')
->format('99999-9999')
```

```php
PtbrPhone::make('phone_number')
->format('(+99)(99)99999-9999')
```

### Money

To create a money input with the Brazilian currency symbol as the prefix, use:

```php
use Leandrocfe\FilamentPtbrFormFields\PtbrMoney;
PtbrMoney::make('price')
```

If you want to remove the prefix, use the prefix() method with a null argument:

```php
PtbrMoney::make('price')
->prefix(null)
```

By default, the mask is removed from the input when it is submitted. If you want to keep the mask, use the dehydrateMask() method with a false argument:

```php
PtbrMoney::make('price')
->dehydrateMask(false)
```

The initial value of the input is '0,00'. If you want to change the initial value, use the initialValue() method with a string argument:

```php
PtbrMoney::make('price')
->initialValue(null)
```

### Address

To integrate with the ViaCep API for CEP validation and address autofill, use:

```php
use Leandrocfe\FilamentPtbrFormFields\PtbrCep;
use Filament\Forms\Components\TextInput;
PtbrCep::make('postal_code')
->viaCep(
mode: 'suffix', // Determines whether the action should be appended to (suffix) or prepended to (prefix) the cep field, or not included at all (none).
errorMessage: 'CEP inválido.', // Error message to display if the CEP is invalid.

/**
* Other form fields that can be filled by ViaCep.
* The key is the name of the Filament input, and the value is the ViaCep attribute that corresponds to it.
* More information: https://viacep.com.br/
*/
setFields: [
'street' => 'logradouro',
'number' => 'numero',
'complement' => 'complemento',
'district' => 'bairro',
'city' => 'localidade',
'state' => 'uf'
]
),

TextInput::make('street'),
TextInput::make('number'),
TextInput::make('complement'),
TextInput::make('district'),
TextInput::make('city'),
TextInput::make('state'),
```

The mode parameter specifies whether the search action should be appended to or prepended to the CEP field, using the values suffix or prefix. Alternatively, you can use the none value with the ->lazy() method to indicate that the other address fields will be automatically filled only when the CEP field loses focus.

## Testing

```bash
Expand All @@ -81,12 +178,12 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security Vulnerabilities

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
If you discover a security vulnerability within this package, please send an e-mail to <leandrocfe@gmail.com>.

## Credits

- [:author_name](https://github.com/:author_username)
- [All Contributors](../../contributors)
- [Leandro Costa Ferreira](https://github.com/leandrocfe)
- [All Contributors](../../contributors)

## License

Expand Down
33 changes: 17 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"name": ":vendor_slug/:package_slug",
"description": ":package_description",
"name": "leandrocfe/filament-ptbr-form-fields",
"description": "Brazilian pt-BR form fields.",
"keywords": [
":vendor_name",
"leandrocfe",
"laravel",
":package_slug"
"filament-ptbr-form-fields"
],
"homepage": "https://github.com/:vendor_slug/:package_slug",
"homepage": "https://github.com/leandrocfe/filament-ptbr-form-fields",
"license": "MIT",
"authors": [
{
"name": ":author_name",
"email": "author@domain.com",
"name": "Leandro Costa Ferreira",
"email": "leandrocfe@gmail.com",
"role": "Developer"
}
],
"require": {
"php": "^8.1",
"spatie/laravel-package-tools": "^1.14.0",
"illuminate/contracts": "^10.0"
"filament/filament": "^2.17",
"illuminate/contracts": "^10.0",
"laravellegends/pt-br-validator": "^10.0",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand All @@ -30,18 +32,17 @@
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"spatie/laravel-ray": "^1.26"
"phpstan/phpstan-phpunit": "^1.0"
},
"autoload": {
"psr-4": {
"VendorName\\Skeleton\\": "src/",
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories/"
"Leandrocfe\\FilamentPtbrFormFields\\": "src/",
"Leandrocfe\\FilamentPtbrFormFields\\Database\\Factories\\": "database/factories/"
}
},
"autoload-dev": {
"psr-4": {
"VendorName\\Skeleton\\Tests\\": "tests/"
"Leandrocfe\\FilamentPtbrFormFields\\Tests\\": "tests/"
}
},
"scripts": {
Expand All @@ -61,10 +62,10 @@
"extra": {
"laravel": {
"providers": [
"VendorName\\Skeleton\\SkeletonServiceProvider"
"Leandrocfe\\FilamentPtbrFormFields\\FilamentPtbrFormFieldsServiceProvider"
],
"aliases": {
"Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton"
"FilamentPtbrFormFields": "Leandrocfe\\FilamentPtbrFormFields\\Facades\\FilamentPtbrFormFields"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions config/filament-ptbr-form-fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

return [];
6 changes: 0 additions & 6 deletions config/skeleton.php

This file was deleted.

Loading

0 comments on commit f9cc6ba

Please sign in to comment.