SlideShare ist ein Scribd-Unternehmen logo
1 von 111
Downloaden Sie, um offline zu lesen
Come JavaScript ha
CAMBIATOCAMBIATO
IL CSSIL CSS Davide Di Pumpo
LET'S START MEAOWLET'S START MEAOW
Parte 1
IL PASSATOIL PASSATO
<style type="text/javascript">
tags.H1.color = "red";
tags.p.fontSize = "20pt";
with (tags.H3) {
color = "green";
}
</style>
GRAZIE A SASS ABBIAMO AVUTO:GRAZIE A SASS ABBIAMO AVUTO:
Le variabili
Le funzioni
I mixin
CON SASS ERAVAMO DIPENDENTI DA RUBYCON SASS ERAVAMO DIPENDENTI DA RUBY
POI, UNA NOTTE DI SETTEMBRE MI SVEGLIAIPOI, UNA NOTTE DI SETTEMBRE MI SVEGLIAI
Era maggio 2009, ma volevo fare la citazione
reference
Così importante che Sass lo hanno
riscritto in Dart
il che ci porta a...
Parte 2
IL PRESENTEIL PRESENTE
Any application that can be written
in JavaScript, will eventually be
written in JavaScript.
ATWOOD'S LAWATWOOD'S LAW
No, non sto parlando di CSS in JS
Lo faremo presto
La vera domanda è, perchè ho bisogno di JS
per scrivere del CSS?
PER RISOLVERCI QUALCHEPER RISOLVERCI QUALCHE
PROBLEMAPROBLEMA
Problema:
SCOPINGSCOPING
.title {
color: red;
}
.title {
color: green;
}
.title {
color: blue;
}
Lo abbiamo risolto con:
BEM, SMACSS, ECC... ECC...BEM, SMACSS, ECC... ECC...
GENTLEMEN'SGENTLEMEN'S
AGREEMENTAGREEMENT
├── Accordion
│   ├── Accordion.html
│   └── Accordion.module.css
├── BadgeStep
│   ├── BadgeStep.html
│   └── BadgeStep.module.css
└── BlogPosts
  ├── BlogPosts.html
  └── BlogPosts.module.css
/* Accordion.module.css */
.title { color: green; }
/* BadgeStep.module.css */
.title { color: green; }
/* BlogPosts.module.css */
.title { color: green; }
/* Accordion.css */
.Accordion--title--axYow2l { color: gr
/* BadgeStep.css */
.BadgeStep--title--9scas2 { color: gre
/* BlogPosts.css */
.BlogPosts--title--Fsvloa { color: gre
html
js
pug
<h1 css-module="title">postcss-modules</h1>
import styles from "./component.module.css";
element.innerHTML =
`<div class="${style.title}">postcss-modules</div>`;
h1(class=css.title) postcss-modules
.
No global scope
Niente conflitti
Dipendenze esplicite
Local styling with CSS Modules - Hugo Giraudel @ From the Fron…
E I WEBE I WEB
COMPONENTS?COMPONENTS?
Aspettiamo Max tra qualche decina di
minuti
Problema:
CONDIVIDERECONDIVIDERE
Tipo tra Sass e JS
$breakpoints: (
small: 640,
medium: 720,
large: 1024
);
COME ACCEDERE A QUESTE PROPERTYCOME ACCEDERE A QUESTE PROPERTY
NEL DOM?NEL DOM?
Non renderizzare intere porzioni di
codice
Utilizzare element query
Far partire o meno chiamate ajax
$breakpoints: (
small: 640,
medium: 720,
large: 1024
);
Come condividerei questo in JS?
export default {
small: 640,
medium: 720,
large: 1024
}
import breakpoints from "./breakpoints.js"
E probabilmente il nostro compilatore Sass
viene lanciato da JS (Gulp, Webpack,
whatelse)
import breakpoints from "./design/breakpoints"
/*...*/
loader: "sass-loader",
options: {
data: `$breakpoints: ${breakpoints}`
}
import breakpoints from "./design/breakpoints"
import flattenObjSass from "js-to-scss"
/*...*/
loader: "sass-loader",
options: {
data: `$breakpoints:
${flattenObjSass(breakpoints)}`
}
Ad esempio, se volessi condividere quanto
accade in un foglio Sass con un altro
foglio Sass?
'env-map($env-sass-map-name, $map: ())':
function (envSassMapName, map) {
if (!env.sass[envSassMapName.getValue()]) {
env.sass[envSassMapName.getValue()] =
new nodeSass.types.Map(0);
}
if (map.getLength()) {
env.sass[envSassMapName.getValue()] = map;
}
E CON ALTRIE CON ALTRI
PROCESSORI CSS?PROCESSORI CSS?
macropodhq/postcss-constants
OK, UN GATTINO PER RIAVERE L'ATTENZIONE:OK, UN GATTINO PER RIAVERE L'ATTENZIONE:
Problema:
CONDIVIDERE A RUNTIMECONDIVIDERE A RUNTIME
Aggiornare il CSS tramite JS
Element.style.left = "42px";
ANCORA PIÙ FACILE GRAZIE ALLEANCORA PIÙ FACILE GRAZIE ALLE
CUSTOM PROPERTIESCUSTOM PROPERTIES
aka CSS variables
Element.style.setProperty(
`--custom`, '42px'
)
Problema:
CODICE RIPETUTOCODICE RIPETUTO
.square {
height: 10px;
width: 10px;
}
// Sass
.square {
@include square(10px);
}
// PostCSS
.square {
@mixin square 10px;
}
.square2 {
size: 10px;
}
module.exports = (mixinNode, value) => {
return {
width: value,
height: value,
}
};
Una domanda sorge spontanea
PERCHÉ POSTCSS?PERCHÉ POSTCSS?
e non uno degli altri?
TESTTEST
import size from '../src/mixins/size.js';
test('Should return CSS rules', () => {
expect(size(null, '64px')).toEqual({
width: '64px',
height: '64px',
})
});
Sandrina Pereira: How can Javascript improve your CSS mixins | …
ANCHE SASS È TESTABILE:ANCHE SASS È TESTABILE: TRUETRUE
@include test-module('Zip [function]') {
@include test('Zips multiple lists int
// Assert the expected results
@include assert-equal(
zip(a b c, 1 2 3),
(a 1, b 2, c 3));
}
Problema:
COMPONENTIZZARECOMPONENTIZZARE
<a href="#" class="btn btn-primary">
Accattatil
</a>
<Button primary>
Accattatil
</Button>
const Button = styled.button`
background: ${props =>
props.primary
? 'palevioletred'
: 'white'
};
color: ${props => props.primary ? 'white' : 'palevi
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
b d 2 lid l i l d
Una domanda sorge spontanea
PERCHÉ NON LEPERCHÉ NON LE
CLASSI?CLASSI?
meno spontanea di prima
Eliminano il global space
Le dipendenze sono esplicite
Condividere costanti è più facile
MA PER ME IL SELLING POINT È...MA PER ME IL SELLING POINT È...
suspense
attesa
momento verità
L'ASTRAZIONEL'ASTRAZIONE
??????
Problema:
REGRESSION TESTREGRESSION TEST
COS'È?COS'È?
BACKSTOPJSBACKSTOPJS
{
"id": "OM Client",
"viewports": [
{"label": "main", "width": 1366, "height": 768}
]
{
"label": "archive",
"url": "https://localhost:9000/archive",
"delay": 2000,
"hideSelectors": ["#loading-bar-new"],
"onBeforeScript": "helpers/localStorageOM.js"
}
module.exports = (chromy, scenario) => {
chromy
.wait('.ic-app')
.click('.introjs-skipbutton');
};
Parte 3
IL FUTUROIL FUTURO
WEB COMPONENTSWEB COMPONENTS
PROJECT HOUDINIPROJECT HOUDINI
CSS PARSER APICSS PARSER API
@apply o @extends a run time!
CSS LAYOUT APICSS LAYOUT API
CSS PAINT APICSS PAINT API
Per farla breve una sorta di Canvas
.bubble {
background: paint('circle');
}
A riguardo
Recap
QUINDI?QUINDI?
USIAMO DA ANNI TOOL PERUSIAMO DA ANNI TOOL PER
MIGLIORARE IL NOSTRO CSSMIGLIORARE IL NOSTRO CSS
JS È GIÀ NELLA NOSTRA BUILD CHAIN,JS È GIÀ NELLA NOSTRA BUILD CHAIN,
USIAMOLO A NOSTRO VANTAGGIOUSIAMOLO A NOSTRO VANTAGGIO
Per risolvere alcuni problemi che possiamo
avere con CSS
DAI RAGA, TUTTE STEDAI RAGA, TUTTE STE
POSSIBILITÀ SONO UNA FIGATAPOSSIBILITÀ SONO UNA FIGATA
GRAZIEGRAZIE
DAVIDE DI PUMPODAVIDE DI PUMPO
Technology -
Co-organizer
MakhBeth on: , ,
I like Cats, Drink, Comics and
Videogames...
Credimi
Milano Frontend
Twitter Github
Internet

Weitere ähnliche Inhalte

Ähnlich wie Come Javascript ha cambiato il CSS

Smau Milano 2102 Maurizio Del Corno
Smau Milano 2102 Maurizio Del CornoSmau Milano 2102 Maurizio Del Corno
Smau Milano 2102 Maurizio Del CornoSMAU
 
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
Corso WebApp iOS - Lezione 06:   Web Development for iOS DevicesCorso WebApp iOS - Lezione 06:   Web Development for iOS Devices
Corso WebApp iOS - Lezione 06: Web Development for iOS DevicesAndrea Picchi
 
Quella sporca dozzina (a cascata) la vendetta
Quella sporca dozzina (a cascata) la vendettaQuella sporca dozzina (a cascata) la vendetta
Quella sporca dozzina (a cascata) la vendettaDavide Di Pumpo
 
Spring, IBatis e Transazioni Aop Nel Jug Avis Web
Spring, IBatis e Transazioni Aop Nel Jug Avis WebSpring, IBatis e Transazioni Aop Nel Jug Avis Web
Spring, IBatis e Transazioni Aop Nel Jug Avis WebMassimiliano Dessì
 
Task automation with grunt
Task automation with gruntTask automation with grunt
Task automation with gruntlucatume
 
S.P.R.I.Te. magazine n.5
S.P.R.I.Te. magazine n.5S.P.R.I.Te. magazine n.5
S.P.R.I.Te. magazine n.5Elvis London
 
How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript Stefano Marchisio
 
jQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerjQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerMatteo Magni
 
Introduzione a jQuery
Introduzione a jQueryIntroduzione a jQuery
Introduzione a jQuerySandro Marcon
 
jQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerjQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerMatteo Magni
 
Write less do more...with jQuery
Write less do more...with jQueryWrite less do more...with jQuery
Write less do more...with jQueryXeDotNet
 
Progetto di Basi di Dati
Progetto di Basi di DatiProgetto di Basi di Dati
Progetto di Basi di Datisegarva
 
jQuery e i suoi plugin
jQuery e i suoi pluginjQuery e i suoi plugin
jQuery e i suoi pluginPasquale Puzio
 

Ähnlich wie Come Javascript ha cambiato il CSS (20)

Smau Milano 2102 Maurizio Del Corno
Smau Milano 2102 Maurizio Del CornoSmau Milano 2102 Maurizio Del Corno
Smau Milano 2102 Maurizio Del Corno
 
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
Corso WebApp iOS - Lezione 06:   Web Development for iOS DevicesCorso WebApp iOS - Lezione 06:   Web Development for iOS Devices
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
 
Web Animation API
Web Animation APIWeb Animation API
Web Animation API
 
Quella sporca dozzina (a cascata) la vendetta
Quella sporca dozzina (a cascata) la vendettaQuella sporca dozzina (a cascata) la vendetta
Quella sporca dozzina (a cascata) la vendetta
 
Spring, IBatis e Transazioni Aop Nel Jug Avis Web
Spring, IBatis e Transazioni Aop Nel Jug Avis WebSpring, IBatis e Transazioni Aop Nel Jug Avis Web
Spring, IBatis e Transazioni Aop Nel Jug Avis Web
 
Yagwto
YagwtoYagwto
Yagwto
 
Task automation with grunt
Task automation with gruntTask automation with grunt
Task automation with grunt
 
S.P.R.I.Te. magazine n.5
S.P.R.I.Te. magazine n.5S.P.R.I.Te. magazine n.5
S.P.R.I.Te. magazine n.5
 
How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript
 
Php mysql3
Php mysql3Php mysql3
Php mysql3
 
jQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerjQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesigner
 
Introduzione a jQuery
Introduzione a jQueryIntroduzione a jQuery
Introduzione a jQuery
 
HTML5
HTML5HTML5
HTML5
 
jQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerjQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesigner
 
Write less do more...with jQuery
Write less do more...with jQueryWrite less do more...with jQuery
Write less do more...with jQuery
 
Progetto di Basi di Dati
Progetto di Basi di DatiProgetto di Basi di Dati
Progetto di Basi di Dati
 
Sinfonia in Domino RE - Integrazione Symphony e Lotus Notes 8.x
Sinfonia in Domino RE - Integrazione Symphony e Lotus Notes 8.xSinfonia in Domino RE - Integrazione Symphony e Lotus Notes 8.x
Sinfonia in Domino RE - Integrazione Symphony e Lotus Notes 8.x
 
Oo Javascript
Oo JavascriptOo Javascript
Oo Javascript
 
Basi Di Dati 05
Basi Di Dati 05Basi Di Dati 05
Basi Di Dati 05
 
jQuery e i suoi plugin
jQuery e i suoi pluginjQuery e i suoi plugin
jQuery e i suoi plugin
 

Mehr von Davide Di Pumpo

Tu chiamalo se vuoi EmotionJS
Tu chiamalo se vuoi EmotionJSTu chiamalo se vuoi EmotionJS
Tu chiamalo se vuoi EmotionJSDavide Di Pumpo
 
Il dato, il browser e il creativo
Il dato, il browser e il creativoIl dato, il browser e il creativo
Il dato, il browser e il creativoDavide Di Pumpo
 
Il curioso caso di Benjamino Bottone
Il curioso caso di Benjamino BottoneIl curioso caso di Benjamino Bottone
Il curioso caso di Benjamino BottoneDavide Di Pumpo
 
Quella sporca dozzina (a cascata)
Quella sporca dozzina (a cascata)Quella sporca dozzina (a cascata)
Quella sporca dozzina (a cascata)Davide Di Pumpo
 
Guida galattica per frontendisti!
Guida galattica per frontendisti!Guida galattica per frontendisti!
Guida galattica per frontendisti!Davide Di Pumpo
 
Web Animation Api MilanoJS 3rd Birthday
Web Animation Api MilanoJS 3rd BirthdayWeb Animation Api MilanoJS 3rd Birthday
Web Animation Api MilanoJS 3rd BirthdayDavide Di Pumpo
 
Stop using Bootstrap please!
Stop using Bootstrap please!Stop using Bootstrap please!
Stop using Bootstrap please!Davide Di Pumpo
 
Understanding flex box CSS Day 2016
Understanding flex box CSS Day 2016Understanding flex box CSS Day 2016
Understanding flex box CSS Day 2016Davide Di Pumpo
 
Guidelines! sorry guys you have to!
Guidelines! sorry guys you have to!Guidelines! sorry guys you have to!
Guidelines! sorry guys you have to!Davide Di Pumpo
 

Mehr von Davide Di Pumpo (13)

Tu chiamalo se vuoi EmotionJS
Tu chiamalo se vuoi EmotionJSTu chiamalo se vuoi EmotionJS
Tu chiamalo se vuoi EmotionJS
 
Il dato, il browser e il creativo
Il dato, il browser e il creativoIl dato, il browser e il creativo
Il dato, il browser e il creativo
 
Take care of your pixel
Take care of your pixelTake care of your pixel
Take care of your pixel
 
Il curioso caso di Benjamino Bottone
Il curioso caso di Benjamino BottoneIl curioso caso di Benjamino Bottone
Il curioso caso di Benjamino Bottone
 
Quella sporca dozzina (a cascata)
Quella sporca dozzina (a cascata)Quella sporca dozzina (a cascata)
Quella sporca dozzina (a cascata)
 
Guida galattica per frontendisti!
Guida galattica per frontendisti!Guida galattica per frontendisti!
Guida galattica per frontendisti!
 
Why meet ups matter
Why meet ups matter Why meet ups matter
Why meet ups matter
 
Web Animation Api MilanoJS 3rd Birthday
Web Animation Api MilanoJS 3rd BirthdayWeb Animation Api MilanoJS 3rd Birthday
Web Animation Api MilanoJS 3rd Birthday
 
Stop using Bootstrap please!
Stop using Bootstrap please!Stop using Bootstrap please!
Stop using Bootstrap please!
 
Design a Design System
Design a Design SystemDesign a Design System
Design a Design System
 
Understanding flex box CSS Day 2016
Understanding flex box CSS Day 2016Understanding flex box CSS Day 2016
Understanding flex box CSS Day 2016
 
Understanding flexbox
Understanding flexboxUnderstanding flexbox
Understanding flexbox
 
Guidelines! sorry guys you have to!
Guidelines! sorry guys you have to!Guidelines! sorry guys you have to!
Guidelines! sorry guys you have to!
 

Come Javascript ha cambiato il CSS