HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="root"></div>
body {
text-align: center;
font: 16px/24px Helvetica, sans-serif;
}
input, textarea, button, select {
font: inherit;
}
input, textarea {
width: 500px;
border: 1px solid #ccc;
padding: 3px;
}
textarea {
font-family: monospace;
}
#root {
text-align: left;
width: 700px;
margin: 40px auto;
padding-bottom: 200px;
}
.result {
position: fixed;
left: 0;
right: 0;
bottom: 0;
height: 180px;
background: #444;
color: #fff;
}
.result .content {
margin: auto;
width: 700px;
}
.result h4 {
margin-bottom: 0;
}
.result textarea {
height: 100px;
background: transparent;
color: #fff;
border: 0;
}
.section h2 {
font-size: 18px;
margin-bottom: 0;
}
.section h2.param {
font-family: monospace;
}
.section p {
margin: 0;
}
.section {
display: block;
margin-bottom: 24px;
}
.section a {
color: blue;
font-weight: bold;
cursor: pointer;
}
.section p a {
font-weight: normal;
}
.section a:hover {
text-decoration: underline;
}
.allFields {
width: 500px;
padding: 3px;
font-style: italic;
margin-bottom: 4px;
color: #666;
}
label.field, label.sort {
display: block;
position: relative;
width: 500px;
height: 23px;
margin-bottom: 3px;
border: 1px solid #ccc;
padding: 3px;
color: #666;
}
label.field input, label.sort input {
position: absolute;
left: 95px;
width: 365px;
border: 0;
padding: 0;
}
label.field button, label.sort button {
position: absolute;
right: 0;
top: 0;
bottom: 0;
width: 30px;
border: 0;
background: #eee;
border-left: 1px solid #ccc;
font: inherit;
color: #444;
}
label.sort input {
width: 265px;
}
label.sort select {
position: absolute;
left: 365px;
}
// http://stackoverflow.com/a/3855394/162210
const queryParams = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=', 2);
if (p.length == 1)
b[p[0]] = "";
else
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
const Encoder = React.createClass({
getInitialState() {
return {
base: queryParams['baseId'] || '',
table: queryParams['tableId'] || '',
fields: [],
filterByFormula: '',
maxRecords: null,
pageSize: null,
sort: [],
view: '',
}
},
_addField() {
const {fields} = this.state;
fields.push('');
this.setState({fields});
},
_addSort() {
const {sort} = this.state;
sort.push({
field: '',
direction: 'asc',
});
this.setState({sort});
},
_renderFields() {
const {fields} = this.state;
if (fields.length === 0) {
return <div className="allFields">All fields will be included by default.</div>;
}
return fields.map((field, i) => {
return (
<label className="field">
Field name:
<input
type="text"
value={field}
onChange={e => {
fields[i] = e.target.value;
this.setState({fields});
}}
/>
<button onClick={() => {
fields.splice(i, 1);
this.setState({fields});
}}>×</button>
</label>
);
});
},
_renderSorts() {
const {sort} = this.state;
if (sort.length === 0) {
return null;
}
return sort.map((sortObj, i) => {
return (
<label className="sort">
Field name:
<input
type="text"
value={sortObj.field}
onChange={e => {
sortObj.field = e.target.value;
this.setState({sort});
}}
/>
<select value={sortObj.direction} onChange={e => {
sortObj.direction = e.target.value;
this.setState({sort});
}}>
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
</select>
<button onClick={() => {
sort.splice(i, 1);
this.setState({sort});
}}>×</button>
</label>
);
});
},
_renderUrl() {
const base = encodeURIComponent(this.state.base || 'YOUR_BASE_ID');
const table = encodeURIComponent(this.state.table || 'YOUR_TABLE_NAME');
const params = {};
if (this.state.fields.length > 0) {
params.fields = this.state.fields;
}
const filterByFormula = this.state.filterByFormula.trim();
if (filterByFormula) {
params.filterByFormula = filterByFormula;
}
const maxRecords = this.state.maxRecords ? parseInt(this.state.maxRecords, 10) : 0;
if (maxRecords) {
params.maxRecords = maxRecords;
}
const pageSize = this.state.pageSize ? parseInt(this.state.pageSize, 10) : 0;
if (pageSize) {
params.pageSize = pageSize;
}
if (this.state.sort.length > 0) {
params.sort = this.state.sort;
}
const view = this.state.view.trim();
if (view) {
params.view = view;
}
const serializedParams = $.param(params);
return `https://api.airtable.com/v0/${base}/${table}?${serializedParams}`;
},
render() {
return (
<div>
<h1>Airtable API URL Encoder</h1>
<p>
You can use this interface to encode the parameters
for listing records in a table.
</p>
<label className="section">
<h2>Base ID</h2>
<p>You can find the base ID on the API page. It begins with 'app'.</p>
<input
type="text"
placeholder="app..."
value={this.state.base}
onChange={e => this.setState({base: e.target.value})}
/>
</label>
<label className="section">
<h2>Table Name</h2>
<input
type="text"
value={this.state.table}
onChange={e => this.setState({table: e.target.value})}
/>
</label>
<div className="section">
<h2 className="param">fields</h2>
<p>Only data for fields whose names are in this list will be included in the records. If you don't need every field, you can use this parameter to reduce the amount of data transferred.</p>
{this._renderFields()}
<a onClick={this._addField}>+ Add field</a>
</div>
<div className="section">
<h2 className="param">filterByFormula</h2>
<p>A <a href="https://support.airtable.com/hc/en-us/articles/203255215-Formula-Field-Reference" target="_blank">formula</a> used to filter records. The formula will be evaluated for each record, and if the result is not <code>0</code>, <code>false</code>, <code>""</code>, <code>NaN</code>, <code>[]</code>, or <code>#Error!</code> the record will be included in the response. If combined with view, only records in that view which satisfy the formula will be returned.</p>
<textarea
value={this.state.filterByFormula}
onChange={e => this.setState({filterByFormula: e.target.value})}
/>
</div>
<div className="section">
<h2 className="param">maxRecords</h2>
<p>The maximum total number of records that will be returned.</p>
<input
type="number"
min="1"
value={this.state.maxRecords}
onChange={e => this.setState({maxRecords: e.target.value})}
/>
</div>
<div className="section">
<h2 className="param">pageSize</h2>
<p>The number of records returned in each request. Must be less than or equal to 100. Default is 100.</p>
<input
type="number"
min="1"
max="100"
value={this.state.pageSize}
onChange={e => this.setState({pageSize: e.target.value})}
/>
</div>
<div className="section">
<h2 className="param">sort</h2>
<p>A list of sort objects that specifies how the records will be ordered.</p>
{this._renderSorts()}
<a onClick={this._addSort}>+ Add sort</a>
</div>
<div className="section">
<h2 className="param">view</h2>
<p>The name or ID of a view in the table. If set, only the records in that view will be returned. The records will be sorted according to the order of the view.</p>
<input
type="text"
value={this.state.view}
onChange={e => this.setState({view: e.target.value})}
/>
</div>
<div className="result">
<div className="content">
<h4>URL</h4>
<textarea value={this._renderUrl()} readonly />
</div>
</div>
</div>
);
}
});
ReactDOM.render(<Encoder />, document.getElementById('root'));
Also see: Tab Triggers