```
---
[.header: alignment(center)]
# Extracting Components
---
[.header: alignment(center)]
## _Do you need to_ extract a component?
---
```twig
{% for item in items %}
{{ item.title }}
{% endfor %}
```
^ Use a loop
---
```twig
Adults
{% include 'class-list' with {
classes: page.classes,
type: 'adults',
} %}
Kids
{% include 'class-list' with {
classes: page.classes,
type: 'kids',
} %}
```
^ Move the duplicate markup into a partial, so there's only one version
Pass data in.
---
```html
Click me!
Click me too!
```
---
```css
# main.css
.button {
@apply .inline-block;
@apply .rounded;
@apply .text-sm;
@apply .py-2;
@apply .px-3;
@apply .text-white;
}
```
---
```html
Click me!
Click me too!
```
---
```less
// table.less
.table-responsive {
@apply .mb-4 .border .w-full;
overflow-x: auto;
overflow-y: hidden;
}
.table-responsive table {
@apply .mb-0 .border-0 .whitespace-no-wrap;
}
.table {
@apply .w-full .table-collapse;
}
.table tr:nth-child(odd) {
@apply .bg-grey-lightest;
}
.table tr th {
@apply .text-left .p-3 .bg-white;
}
.table td {
@apply .px-3 .py-3 .border-t;
}
```
---
[.header: #53B0EB]
# Advantages
- Quick to prototype and make changes
- Write less CSS
- More consistency
- Easy to customise, promote to components
- Mix and match with normal CSS
- Easy to write reusable plugins
- Use PurgeCSS to remove unused classes
^ Do more with browser dev tools
Only picking from pre-defined colours, widths. No magic numbers.
Less ramp-up time as using the same framework on different sites.
Same classes, but no visual similarities like with other frameworks like Bootstrap
---
[.header: #53B0EB]
# Disadvantages
- Extra build tools and steps
- Lots of classes in markup
- Large file size by default
^ - Need a build tool (Gulp, Grunt, Webpack) to build CSS
---
![inline](images/refactoring-ui.png)
---
![inline](images/laravel-nova.png)
---
![inline](images/spatie.png)
---
![inline](images/php-south-wales.png)
---
[.build-lists: false]
[.header: #53B0EB]
# Resources
- tailwindcss.com
- tailwindcomponents.com
- github.com/merchedhq/awesome-tailwindcss
- youtube.com/adamwathan
- github.com/opdavies/oliverdavies.uk
- github.com/phpsw/phpsw-ng
---
[.header: alignment(center)]
# Thanks!
### _@opdavies_
### _oliverdavies.uk_