Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TwitterBoostrap v5 #3

Merged
merged 14 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/coding-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Coding Style

on: [push, pull_request]

jobs:
nette_cc:
name: Nette Code Checker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress
- run: php temp/code-checker/code-checker -d src --strict-types --no-progress --ignore expected


nette_cs:
name: Nette Coding Standard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress
- run: php temp/coding-standard/ecs check src tests
18 changes: 18 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Static Analysis (only informative)

on: [push, pull_request]

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- run: composer install --no-progress --prefer-dist
- run: composer phpstan
continue-on-error: true # is only informative
45 changes: 45 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1', '8.2', '8.3']

fail-fast: false

name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- run: composer install --no-progress --prefer-dist
- run: vendor/bin/tester tests -s -C
- if: failure()
uses: actions/upload-artifact@v3
with:
name: output
path: tests/**/output

code_coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- run: composer install --no-progress --prefer-dist
- run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src
- run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
- env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: php php-coveralls.phar --verbose --config tests/.coveralls.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/nette-code-checker
/nette-coding-standard
/tests/tests/output
/package-lock.json
258 changes: 255 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# nette-form-renderer
[![Build Status](https://app.travis-ci.com/venca-x/nette-form-renderer.svg?branch=master)](https://app.travis-ci.com/venca-x/nette-form-renderer)
[![Tests](https://github.com/nette/forms/workflows/Tests/badge.svg?branch=master)](https://github.com/venca-x/nette-form-renderer/actions)
[![Coverage Status](https://coveralls.io/repos/github/venca-x/nette-form-renderer/badge.svg?branch=master)](https://coveralls.io/github/venca-x/nette-form-renderer?branch=master)
[![Latest Stable Version](https://poser.pugx.org/venca-x/nette-form-renderer/v/stable)](https://packagist.org/packages/venca-x/nette-form-renderer)
[![Latest Unstable Version](https://poser.pugx.org/venca-x/nette-form-renderer/v/unstable)](https://packagist.org/packages/venca-x/nette-form-renderer)
[![Total Downloads](https://poser.pugx.org/venca-x/nette-form-renderer/downloads)](https://packagist.org/packages/venca-x/nette-form-renderer)
[![License](https://poser.pugx.org/venca-x/nette-form-renderer/license)](https://packagist.org/packages/venca-x/nette-form-renderer)

Form renderer for Nette Forms - TwitterBootstrap v4
Form renderer for Nette Forms - TwitterBootstrap v5 and v4

## Installation
Install with composer:
```
composer require venca-x/nette-form-renderer
composer require venca-x/nette-form-renderer:dev-master
```

Expand All @@ -21,7 +22,258 @@ Types of orientation form
* Horizontal
* Inline

Default is vertical form orientation.
Vertical form orientation is default.

# Boostrap v5 rendering

## Vertical orientation form
```php
$form = new Form;
$form->setRenderer(new VencaX\NetteFormRenderer\BootstrapRendererV5());

$form->addEmail('exampleInputEmail1', 'Email address:')
->setHtmlAttribute('placeholder', 'Enter email')
->setOption('description', 'We\'ll never share your email with anyone else.');
$form->addPassword('exampleInputPassword1', 'Password')
->setHtmlAttribute('placeholder', 'Password');
$form->addCheckbox('checkbox', 'Check me out');
$form->addCheckbox('checkbox2', 'Check me out2');

$form->addRadioList('country', 'Country', [
'cz' => 'Česká republika',
'sk' => 'Slovensko',
'eu' => 'EU',
]);

$form->addEmail('exampleInputEmail2', 'Email address')
->setHtmlAttribute('placeholder', '[email protected]');

$form->addSelect('exampleSelect', 'Example select', [
'1',
'2',
'3',
'4',
'5', ]);

$form->addMultiSelect('exampleMultipleSelect', 'Example multiple select', [
'1',
'2',
'3',
'4',
'5', ]);

$form->addTextArea('textarea', 'Example textarea');

$form->addUpload('upload', 'Example upload');

$form->addMultiUpload('multiUpload', 'Example multiUpload');


//sizes
$form->addEmail('formControlLg', '.form-control-lg')
->setHtmlAttribute('class', 'form-control-lg')
->setHtmlAttribute('placeholder', '.form-control-lg');

$form->addEmail('formControl', '.form-control')
->setHtmlAttribute('placeholder', 'Default input');

$form->addEmail('formControlSm', '.form-control-sm')
->setHtmlAttribute('class', 'form-control-sm')
->setHtmlAttribute('placeholder', '.form-control-sm');


//sizes select
$form->addSelect('largeSelect', 'Large select', ['Large select'])
->setHtmlAttribute('class', 'form-control-lg');

$form->addSelect('defaultSelect', ' Default select', ['Default select']);

$form->addSelect('smallSelect', 'Small select', ['Small select'])
->setHtmlAttribute('class', 'form-control-sm');


//disables
$form->addText('disabled', 'Disabled:')
->setHtmlAttribute('placeholder', 'Disabled input here…')
->setDisabled(true);


$form->addSubmit('submit', 'Submit')->setHtmlAttribute('class', 'btn btn-primary');

return $form;
```

## Vertical orientation form - radios and checkboxes inline
```php
$form = new Form;
$form->setRenderer(new VencaX\NetteFormRenderer\BootstrapRendererV5());

$form->addCheckbox('mondayCheckbox', 'Monday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('tuesdayCheckbox', 'Tuesday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('wednesdayCheckbox', 'Wednesday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('thurstdayCheckbox', 'Thurstday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('fridayCheckbox', 'Friday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('saturdayCheckbox', 'Saturday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('sundayCheckbox', 'Sunday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);

$form->addRadioList('weekRadionline', 'Week radio 2', [
'monday' => 'Monday',
'tuesday' => 'Tuesday',
'wednesday' => 'Wednesday',
'thurstday' => 'Thurstday',
'friday' => 'Friday',
'saturday' => 'Saturday',
'sunday' => 'Sunday',
])->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);

$form->addSubmit('submit', 'Submit')->setHtmlAttribute('class', 'btn btn-primary');

return $form;
```

## Horizontal orientation form
```php
$form = new Form;
$form->setRenderer(new VencaX\NetteFormRenderer\BootstrapRendererV5());

//horizontal form
$renderer = $form->getRenderer();
$renderer->setFormHorizontalOrientation();

//$renderer->setFormControlLabelWidth('col-sm-6');
//$renderer->setFormControlContainerWidth('col-sm-6');

$form->addEmail('exampleInputEmail1', 'Email address:')
->setHtmlAttribute('placeholder', 'Enter email')
->setOption('description', 'We\'ll never share your email with anyone else.');
$form->addPassword('exampleInputPassword1', 'Password')
->setHtmlAttribute('placeholder', 'Password');
$form->addCheckbox('checkbox', 'Check me out');
$form->addCheckbox('checkbox2', 'Check me out2');

$form->addRadioList('country', 'Country', [
'cz' => 'Česká republika',
'sk' => 'Slovensko',
'eu' => 'EU',
]);

$form->addEmail('exampleInputEmail2', 'Email address')
->setHtmlAttribute('placeholder', '[email protected]');

$form->addSelect('exampleSelect', 'Example select', [
'1',
'2',
'3',
'4',
'5', ]);

$form->addMultiSelect('exampleMultipleSelect', 'Example multiple select', [
'1',
'2',
'3',
'4',
'5', ]);

$form->addTextArea('textarea', 'Example textarea');

$form->addUpload('upload', 'Example upload');

$form->addMultiUpload('multiUpload', 'Example multiUpload');

//sizes
$form->addEmail('formControlLg', '.form-control-lg')
->setHtmlAttribute('class', 'form-control-lg')
->setHtmlAttribute('placeholder', '.form-control-lg');

$form->addEmail('formControl', '.form-control')
->setHtmlAttribute('placeholder', 'Default input');

$form->addEmail('formControlSm', '.form-control-sm')
->setHtmlAttribute('class', 'form-control-sm')
->setHtmlAttribute('placeholder', '.form-control-sm');


//sizes select
$form->addSelect('largeSelect', 'Large select', ['Large select'])
->setHtmlAttribute('class', 'form-control-lg');

$form->addSelect('defaultSelect', ' Default select', ['Default select']);

$form->addSelect('smallSelect', 'Small select', ['Small select'])
->setHtmlAttribute('class', 'form-control-sm');


//disables
$form->addText('disabled', 'Disabled:')
->setHtmlAttribute('placeholder', 'Disabled input here…')
->setDisabled(true);


$form->addSubmit('submit', 'Submit')->setHtmlAttribute('class', 'btn btn-primary');

return $form;
```

## Horizontal orientation form - radios and checkboxes inline
**It is not possible to place checkboxes on one line**, only radios inline.
```php
$form = new Form;
$form->setRenderer(new VencaX\NetteFormRenderer\BootstrapRendererV5());

//horizontal form
$renderer = $form->getRenderer();
$renderer->setFormHorizontalOrientation();

//$renderer->setFormControlLabelWidth('col-sm-6');
//$renderer->setFormControlContainerWidth('col-sm-6');

//!!!!!!!!! this orientation **don't work** !!!!!!!!!!!!!!!!!
$form->addCheckbox('mondayCheckbox', 'Monday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('tuesdayCheckbox', 'Tuesday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('wednesdayCheckbox', 'Wednesday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('thurstdayCheckbox', 'Thurstday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('fridayCheckbox', 'Friday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('saturdayCheckbox', 'Saturday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);
$form->addCheckbox('sundayCheckbox', 'Sunday')->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);

$form->addRadioList('weekRadionline', 'Week radio 2', [
'monday' => 'Monday',
'tuesday' => 'Tuesday',
'wednesday' => 'Wednesday',
'thurstday' => 'Thurstday',
'friday' => 'Friday',
'saturday' => 'Saturday',
'sunday' => 'Sunday',
])->setOption('orientation', VencaX\NetteFormRenderer\BootstrapRendererV5::FORM_CHECK_INLINE);

$form->addSubmit('submit', 'Submit')->setHtmlAttribute('class', 'btn btn-primary');

return $form;
```

## Inline orientation form
```php
$form = new Form;
$form->setRenderer(new VencaX\NetteFormRenderer\BootstrapRendererV5());

//inline form
$renderer = $form->getRenderer();
$renderer->setFormInline();

$form->addEmail('loginemail', 'E-mail address:')
->setHtmlAttribute('placeholder', 'Enter e-mail');
$form->addPassword('password', 'Password')
->setHtmlAttribute('placeholder', 'Password');
$form->addCheckbox('checkbox', 'Check me out');

$form->addSubmit('submit', 'Submit')->setHtmlAttribute('class', 'btn btn-primary');

return $form;
```



# Boostrap v4 rendering

## Vertical orientation form
```php
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "venca-x/nette-form-renderer",
"description": "Nette form renderer (Twitter Bootstrap 4)",
"description": "Nette form renderer (Twitter bootstrap v5 and v4)",
"license": ["MIT", "BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
"authors": [
{
Expand All @@ -13,8 +13,7 @@
"nette/forms": "^3.0"
},
"require-dev": {
"nette/tester": "^2.0",
"phpstan/phpstan": "^0.12.45@dev"
"nette/tester": "^2.0"
},
"autoload": {
"classmap": [
Expand Down
Loading
Loading