Skip to content

Commit f9cc6ba

Browse files
committed
Merge branch 'release/0.1.0'
2 parents 6a668f4 + 7fd95b0 commit f9cc6ba

27 files changed

+456
-426
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Ask a question
4-
url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a
4+
url: https://github.com/leandrocfe/filament-ptbr-form-fields/discussions/new?category=q-a
55
about: Ask the community for help
66
- name: Request a feature
7-
url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas
7+
url: https://github.com/leandrocfe/filament-ptbr-form-fields/discussions/new?category=ideas
88
about: Share ideas for new features
99
- name: Report a security issue
10-
url: https://github.com/:vendor_name/:package_name/security/policy
10+
url: https://github.com/leandrocfe/filament-ptbr-form-fields/security/policy
1111
about: Learn how to notify us for sensitive bugs

.github/workflows/update-changelog.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Changelog
22

3-
All notable changes to `:package_name` will be documented in this file.
3+
All notable changes to `filament-ptbr-form-fields` will be documented in this file.

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) :vendor_name <author@domain.com>
3+
Copyright (c) leandrocfe <leandrocfe@gmail.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 139 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,167 @@
1-
# :package_description
1+
# Brazilian pt-BR form fields.
22

3-
[![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)
4-
[![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)
5-
[![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)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
7-
<!--delete-->
8-
---
9-
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
3+
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).
104

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

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

21-
[<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)
9+
## Installation
2210

23-
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).
11+
You can install the package via Composer:
2412

25-
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).
13+
```bash
14+
composer require leandrocfe/filament-ptbr-form-fields
15+
```
2616

27-
## Installation
17+
## Usage
2818

29-
You can install the package via composer:
19+
### CPF / CNPJ
3020

31-
```bash
32-
composer require :vendor_slug/:package_slug
21+
To create a dynamic input that accepts either CPF or CNPJ, use:
22+
23+
```php
24+
use Leandrocfe\FilamentPtbrFormFields\PtbrCpfCnpj;
25+
PtbrCpfCnpj::make('cpf_or_cnpj')
3326
```
3427

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

37-
```bash
38-
php artisan vendor:publish --tag=":package_slug-migrations"
39-
php artisan migrate
30+
```php
31+
PtbrCpfCnpj::make('cpf_or_cnpj')
32+
->rule('cpf_ou_cnpj')
4033
```
4134

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

44-
```bash
45-
php artisan vendor:publish --tag=":package_slug-config"
37+
```php
38+
//CPF
39+
PtbrCpfCnpj::make('cpf')
40+
->cpf()
41+
```
42+
43+
```php
44+
//CNPJ
45+
PtbrCpfCnpj::make('cnpj')
46+
->cnpj()
4647
```
4748

48-
This is the contents of the published config file:
49+
You can also add validation to these fields as well:
4950

5051
```php
51-
return [
52-
];
52+
//CPF with validation
53+
PtbrCpfCnpj::make('cpf')
54+
->cpf()
55+
->rule('cpf')
5356
```
5457

55-
Optionally, you can publish the views using
58+
```php
59+
//CNPJ with validation
60+
PtbrCpfCnpj::make('cnpj')
61+
->cnpj()
62+
->rule('cnpj')
63+
```
5664

57-
```bash
58-
php artisan vendor:publish --tag=":package_slug-views"
65+
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:
66+
67+
```php
68+
PtbrCpfCnpj::make('cpf')
69+
->cpf('999999999-99')
5970
```
6071

61-
## Usage
72+
```php
73+
PtbrCpfCnpj::make('cnpj')
74+
->cnpj('99999999/9999-57')
75+
```
76+
77+
### Phone number
78+
79+
To create a dynamic input that formats phone numbers with DDD, use:
6280

6381
```php
64-
$variable = new VendorName\Skeleton();
65-
echo $variable->echoPhrase('Hello, VendorName!');
82+
use Leandrocfe\FilamentPtbrFormFields\PtbrPhone;
83+
PtbrPhone::make('phone_number')
6684
```
6785

86+
If you want to use a custom phone number format, use the format() method with a string argument representing the desired format:
87+
88+
```php
89+
PtbrPhone::make('phone_number')
90+
->format('99999-9999')
91+
```
92+
93+
```php
94+
PtbrPhone::make('phone_number')
95+
->format('(+99)(99)99999-9999')
96+
```
97+
98+
### Money
99+
100+
To create a money input with the Brazilian currency symbol as the prefix, use:
101+
102+
```php
103+
use Leandrocfe\FilamentPtbrFormFields\PtbrMoney;
104+
PtbrMoney::make('price')
105+
```
106+
107+
If you want to remove the prefix, use the prefix() method with a null argument:
108+
109+
```php
110+
PtbrMoney::make('price')
111+
->prefix(null)
112+
```
113+
114+
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:
115+
116+
```php
117+
PtbrMoney::make('price')
118+
->dehydrateMask(false)
119+
```
120+
121+
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:
122+
123+
```php
124+
PtbrMoney::make('price')
125+
->initialValue(null)
126+
```
127+
128+
### Address
129+
130+
To integrate with the ViaCep API for CEP validation and address autofill, use:
131+
132+
```php
133+
use Leandrocfe\FilamentPtbrFormFields\PtbrCep;
134+
use Filament\Forms\Components\TextInput;
135+
PtbrCep::make('postal_code')
136+
->viaCep(
137+
mode: 'suffix', // Determines whether the action should be appended to (suffix) or prepended to (prefix) the cep field, or not included at all (none).
138+
errorMessage: 'CEP inválido.', // Error message to display if the CEP is invalid.
139+
140+
/**
141+
* Other form fields that can be filled by ViaCep.
142+
* The key is the name of the Filament input, and the value is the ViaCep attribute that corresponds to it.
143+
* More information: https://viacep.com.br/
144+
*/
145+
setFields: [
146+
'street' => 'logradouro',
147+
'number' => 'numero',
148+
'complement' => 'complemento',
149+
'district' => 'bairro',
150+
'city' => 'localidade',
151+
'state' => 'uf'
152+
]
153+
),
154+
155+
TextInput::make('street'),
156+
TextInput::make('number'),
157+
TextInput::make('complement'),
158+
TextInput::make('district'),
159+
TextInput::make('city'),
160+
TextInput::make('state'),
161+
```
162+
163+
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.
164+
68165
## Testing
69166

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

82179
## Security Vulnerabilities
83180

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

86183
## Credits
87184

88-
- [:author_name](https://github.com/:author_username)
89-
- [All Contributors](../../contributors)
185+
- [Leandro Costa Ferreira](https://github.com/leandrocfe)
186+
- [All Contributors](../../contributors)
90187

91188
## License
92189

composer.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
{
2-
"name": ":vendor_slug/:package_slug",
3-
"description": ":package_description",
2+
"name": "leandrocfe/filament-ptbr-form-fields",
3+
"description": "Brazilian pt-BR form fields.",
44
"keywords": [
5-
":vendor_name",
5+
"leandrocfe",
66
"laravel",
7-
":package_slug"
7+
"filament-ptbr-form-fields"
88
],
9-
"homepage": "https://github.com/:vendor_slug/:package_slug",
9+
"homepage": "https://github.com/leandrocfe/filament-ptbr-form-fields",
1010
"license": "MIT",
1111
"authors": [
1212
{
13-
"name": ":author_name",
14-
"email": "author@domain.com",
13+
"name": "Leandro Costa Ferreira",
14+
"email": "leandrocfe@gmail.com",
1515
"role": "Developer"
1616
}
1717
],
1818
"require": {
1919
"php": "^8.1",
20-
"spatie/laravel-package-tools": "^1.14.0",
21-
"illuminate/contracts": "^10.0"
20+
"filament/filament": "^2.17",
21+
"illuminate/contracts": "^10.0",
22+
"laravellegends/pt-br-validator": "^10.0",
23+
"spatie/laravel-package-tools": "^1.14.0"
2224
},
2325
"require-dev": {
2426
"laravel/pint": "^1.0",
@@ -30,18 +32,17 @@
3032
"pestphp/pest-plugin-laravel": "^2.0",
3133
"phpstan/extension-installer": "^1.1",
3234
"phpstan/phpstan-deprecation-rules": "^1.0",
33-
"phpstan/phpstan-phpunit": "^1.0",
34-
"spatie/laravel-ray": "^1.26"
35+
"phpstan/phpstan-phpunit": "^1.0"
3536
},
3637
"autoload": {
3738
"psr-4": {
38-
"VendorName\\Skeleton\\": "src/",
39-
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories/"
39+
"Leandrocfe\\FilamentPtbrFormFields\\": "src/",
40+
"Leandrocfe\\FilamentPtbrFormFields\\Database\\Factories\\": "database/factories/"
4041
}
4142
},
4243
"autoload-dev": {
4344
"psr-4": {
44-
"VendorName\\Skeleton\\Tests\\": "tests/"
45+
"Leandrocfe\\FilamentPtbrFormFields\\Tests\\": "tests/"
4546
}
4647
},
4748
"scripts": {
@@ -61,10 +62,10 @@
6162
"extra": {
6263
"laravel": {
6364
"providers": [
64-
"VendorName\\Skeleton\\SkeletonServiceProvider"
65+
"Leandrocfe\\FilamentPtbrFormFields\\FilamentPtbrFormFieldsServiceProvider"
6566
],
6667
"aliases": {
67-
"Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton"
68+
"FilamentPtbrFormFields": "Leandrocfe\\FilamentPtbrFormFields\\Facades\\FilamentPtbrFormFields"
6869
}
6970
}
7071
},

config/filament-ptbr-form-fields.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
return [];

config/skeleton.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)