JSFiddle - React, Tailwind, and code Playground
by dipeshbeckham
HTML
<script src="https://js.stripe.com/v3/"></script>
<link rel="stylesheet" href="https://raw.githubusercontent.com/stripe/elements-examples/master/css/base.css">
<div class="cell example example2" id="example-2">
<form>
<div data-locale-reversible>
<div class="row">
<div class="field">
<input id="example2-address" data-tid="elements_examples.form.address_placeholder" class="input empty" type="text" placeholder="185 Berry St" required="" autocomplete="address-line1">
<label for="example2-address" data-tid="elements_examples.form.address_label">Address</label>
<div class="baseline"></div>
</div>
</div>
<div class="row" data-locale-reversible>
<div class="field half-width">
<input id="example2-city" data-tid="elements_examples.form.city_placeholder" class="input empty" type="text" placeholder="San Francisco" required="" autocomplete="address-level2">
<label for="example2-city" data-tid="elements_examples.form.city_label">City</label>
<div class="baseline"></div>
</div>
<div class="field quarter-width">
<input id="example2-state" data-tid="elements_examples.form.state_placeholder" class="input empty" type="text" placeholder="CA" required="" autocomplete="address-level1">
<label for="example2-state" data-tid="elements_examples.form.state_label">State</label>
<div class="baseline"></div>
</div>
<div class="field quarter-width">
<input id="example2-zip" data-tid="elements_examples.form.postal_code_placeholder" class="input empty" type="text" placeholder="94107" required="" autocomplete="postal-code">
<label for="example2-zip" data-tid="elements_examples.form.postal_code_label">ZIP</label>
<div class="baseline"></div>
...
CSS
.example.example2 {
background-color: #fff;
}
.example.example2 * {
font-family: Source Code Pro, Consolas, Menlo, monospace;
font-size: 16px;
font-weight: 500;
}
.example.example2 .row {
display: -ms-flexbox;
display: flex;
margin: 0 5px 10px;
}
.example.example2 .field {
position: relative;
width: 100%;
height: 50px;
margin: 0 10px;
}
.example.example2 .field.half-width {
width: 50%;
}
.example.example2 .field.quarter-width {
width: calc(25% - 10px);
}
.example.example2 .baseline {
position: absolute;
width: 100%;
height: 1px;
left: 0;
bottom: 0;
background-color: #cfd7df;
transition: background-color 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.example.example2 label {
position: absolute;
width: 100%;
left: 0;
bottom: 8px;
color: #cfd7df;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
transform-origin: 0 50%;
cursor: text;
pointer-events: none;
transition-property: color, transform;
transition-duration: 0.3s;
transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
}
.example.example2 .input {
position: absolute;
width: 100%;
left: 0;
bottom: 0;
padding-bottom: 7px;
color: #32325d;
background-color: transparent;
}
.example.example2 .input::-webkit-input-placeholder {
color: transparent;
transition: color 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.example.example2 .input::-moz-placeholder {
color: transparent;
transition: color 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.example.example2 .input:-ms-input-placeholder {
color: transparent;
transition: color 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.example.example2 .input.StripeElement {
opacity: 0;
transition: opacity 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
will-change: opacity;
}
.example.example2 .input.focused,
.example.example2 .input:not(.empty) {
opacity: 1;
}
.example.example2 .input.focused::-webkit-input-placeholder,
.example.example2...
JavaScript
var stripe = Stripe('pk_test_6pRNASCoBOKtIshFeQd4XMUh');
(function() {
'use strict';
var elements = stripe.elements({
fonts: [
{
cssSrc: 'https://fonts.googleapis.com/css?family=Source+Code+Pro',
},
],
// Stripe's examples are localized to specific languages, but if
// you wish to have Elements automatically detect your user's locale,
// use `locale: 'auto'` instead.
locale: window.__exampleLocale
});
// Floating labels
var inputs = document.querySelectorAll('.cell.example.example2 .input');
Array.prototype.forEach.call(inputs, function(input) {
input.addEventListener('focus', function() {
input.classList.add('focused');
});
input.addEventListener('blur', function() {
input.classList.remove('focused');
});
input.addEventListener('keyup', function() {
if (input.value.length === 0) {
input.classList.add('empty');
} else {
input.classList.remove('empty');
}
});
});
var elementStyles = {
base: {
color: '#32325D',
fontWeight: 500,
fontFamily: 'Source Code Pro, Consolas, Menlo, monospace',
fontSize: '16px',
fontSmoothing: 'antialiased',
'::placeholder': {
color: '#CFD7DF',
},
':-webkit-autofill': {
color: '#e39f48',
},
},
invalid: {
color: '#E25950',
'::placeholder': {
color: '#FFCCA5',
},
},
};
var elementClasses = {
focus: 'focused',
empty: 'empty',
invalid: 'invalid',
};
var cardNumber = elements.create('cardNumber', {
style: elementStyles,
classes: elementClasses,
});
cardNumber.mount('#example2-card-number');
var cardExpiry = elements.create('cardExpiry', {
style: elementStyles,
classes: elementClasses,
});
cardExpiry.mount('#example2-card-expiry');
var cardCvc = elements.create('cardCvc', {
style: elementStyles,
classes: elementClasses,
});
...