JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<div id="app"/>
.FittingRoom {
font-family: Helvetica;
text-align: center;
background-color: #ffffff;
width: 150px;
color: #111111;
margin: 4px;
border: 1px solid #aaaaaa;
border-top: 0 solid #aaaaaa;
position: relative;
&__Container {
padding: 16px 16px 24px 16px;
}
&__Label {
margin: 0 auto;
font-size: 24px;
padding: 4px;
text-align: center;
height: 32px;
width: 32px;
border-radius: 9999px;
background-color: #aaaaaa;
color: white;
}
&__Status {
margin-top: 8px;
padding: 8px 0;
font-size: 18px;
}
&__Timer {
padding: 8px 0;
font-size: 16px;
}
}
.FittingRoom--Open {
color: #66A97A;
.FittingRoom__Container {
border-top: 8px solid #66A97A;
}
.FittingRoom__StatusBar {
background-color: #66A97A;
}
.FittingRoom__Label {
background-color: #66A97A;
}
}
.FittingRoom--Occupied {
.FittingRoom__Container {
border-top: 8px solid #ff0000;
}
.FittingRoom__Label {
background-color: #ff0000;
}
}
.FittingRoom--Closed {
color: #aaaaaa;
.FittingRoom__Container {
border-top: 8px solid #aaaaaa;
}
.FittingRoom__Label {
background-color: #aaaaaa;
}
}
.FittingRoomActionsMenu {
position: absolute;
top: 80%;
left: 0;
height: auto;
z-index: 3;
&__Arrow {
position: absolute;
top: -16px;
left: 0px;
width: 0;
height: 0;
border-left: 16px solid transparent;
border-right: 16px solid transparent;
border-bottom: 16px solid #cccccc;
}
&__InnerArrow {
position: absolute;
top: 1px;
left: -15px;
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-bottom: 15px solid #ffffff;
}
&__Body {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
background-color: #ffffff;
list-style: none;
padding: 0;
margin: 0;
&__Item {
font-size: 16px;
color: #111111;
padding: 16px;
border-bottom: 1px solid #cccccc;
&:hover {
background-color: #eeeeee;
}
}
}
}
class FittingRoom extends React.Component {
constructor (props) {
super(props)
this.state = {
shouldShowActionsMenu: false
}
this.toggleActionsMenu = this.toggleActionsMenu.bind(this)
}
toggleActionsMenu () {
this.setState({shouldShowActionsMenu: !this.state.shouldShowActionsMenu})
}
isOccupied (fittingRoom) {
return !_.isEmpty(fittingRoom.fittingRoomTicket)
}
isOpen (fittingRoom) {
return fittingRoom.open === true
}
renderOccupiedFittingRoom (fittingRoom) {
let walkIn = fittingRoom.fittingRoomTicket.walkIn
return (
<div className='FittingRoom__Container'>
<div className='FittingRoom__Label'>
{fittingRoom.label}
</div>
<div className='FittingRoom__Status'>
{walkIn.firstName} {walkIn.lastName}
</div>
<div className='FittingRoom__Timer'>
{formatTimeElapsed(fittingRoom.fittingRoomTicket.startTime)}
</div>
{this.state.shouldShowActionsMenu && <FittingRoomActionsMenu
toggleActionsMenu={this.toggleActionsMenu}
adjustFittingRoom={() => { this.props.removeWalkIn(walkIn, fittingRoom.fittingRoomTicket) }}
adjustFittingRoomText={'Mark as Done'} />
}
</div>
)
}
renderFittingRoom (fittingRoom) {
return (
<div className='FittingRoom__Container'>
<div className='FittingRoom__Label'>
{fittingRoom.label}
</div>
<div className='FittingRoom__Status'>
{fittingRoom.open ? 'Open' : 'Closed'}
</div>
{this.state.shouldShowActionsMenu && <FittingRoomActionsMenu
toggleActionsMenu={this.toggleActionsMenu}
adjustFittingRoom={() => this.props.updateFittingRoom(fittingRoom)}
adjustFittingRoomText={fittingRoom.open ? 'Close Fitting Room' : 'Open Fitting Room'} />}
</div>
)
}
render () {
let {fittingRoom} = this.props
let status
let fittingRoomComponent
if (this.isOccupied(fittingRoom)) {
status = 'Occupied'
fittingRoomComponent = this.renderOccupiedFittingRoom(fittingRoom)
} else if (this.isOpen(fittingRoom)) {
status = 'Open'
fittingRoomComponent = this.renderFittingRoom(fittingRoom)
} else {
status = 'Closed'
fittingRoomComponent = this.renderFittingRoom(fittingRoom)
}
return (
<div className={`FittingRoom FittingRoom--${status}`} onClick={this.toggleActionsMenu}>
{fittingRoomComponent}
</div>
)
}
}
class FittingRoomActionsMenu extends React.Component {
constructor (props) {
super(props)
this.setWrapperRef = this.setWrapperRef.bind(this)
this.handleClickOutside = this.handleClickOutside.bind(this)
}
componentDidMount () {
document.addEventListener('mousedown', this.handleClickOutside)
}
componentWillUnMount () {
document.removeEventListener('mousedown', this.handleClickOutside)
}
setWrapperRef (node) {
this.wrapperRef = node
}
handleClickOutside (event) {
// THIS ALLOWS THE TOGGLE TO REMAIN FUNCTIONAL WHEN THE MENU IS OPEN
let toggles = Array.prototype.slice.call(document.querySelectorAll('.FittingRoom'))
if (this.wrapperRef && !this.wrapperRef.contains(event.target) && !toggles.some((t) => t.contains(event.target))) {
this.props.toggleActionsMenu()
}
}
render () {
return (
<div ref={this.setWrapperRef}>
<div className='FittingRoomActionsMenu'>
<div className='FittingRoomActionsMenu__Arrow'>
<div className='FittingRoomActionsMenu__InnerArrow' />
</div>
<ul className='FittingRoomActionsMenu__Body'>
<li className='FittingRoomActionsMenu__Body__Item' onClick={this.props.adjustFittingRoom}>
{this.props.adjustFittingRoomText}
</li>
</ul>
</div>
</div>
)
}
}
let fittingRoom = {
label: "1",
open: true,
fittingRoomTicket: null
}
ReactDOM.render(<FittingRoom fittingRoom={fittingRoom}/>,
document.getElementById('app'))
Also see: Tab Triggers