Skip to content

Instantly share code, notes, and snippets.

View NoamELB's full-sized avatar
🦄
magical

Noam Elboim NoamELB

🦄
magical
  • TLV
View GitHub Profile
@NoamELB
NoamELB / index.scss
Last active October 20, 2018 22:25
tabs example
@import "../../../../SASS/lib/core";
@import "../../Cards/Card/mixins";
.tabs {
padding: 0;
border: $constants-border;
border-radius: 8px;
.tabs_header {
display: flex;
@NoamELB
NoamELB / updateHeight.js
Created November 18, 2017 17:33
update height on a Collapse component
updateHeight(isOpen) {
if (isOpen) {
this.containerEl.style.height = `${this.contentEl.scrollHeight}px`;
} else {
this.containerEl.style.height = '0px';
}
}
@NoamELB
NoamELB / unleashed.js
Last active November 18, 2017 18:26
unleashed component
export default class UnleashedOne extends React.Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
}
onChange(e) {
this.props.onChange(e.target.value);
}
render () {
return (
@NoamELB
NoamELB / leashed.js
Created November 18, 2017 18:34
leashed component
export default class LeashedOne extends React.Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.onChangeDebounce = _.debounce(value => this.props.onChange(value), 300);
}
onChange(e) {
this.onChangeDebounce(e.target.value);
}
render () {
@NoamELB
NoamELB / ShouldNotUpdate.js
Last active January 28, 2019 01:31
component that should not update
class ShouldNotUpdate extends React.Component {
constructor(props) {
super(props);
this.counter = 0;
}
shouldComponentUpdate(nextProps, nextState) {
return this.props.children !== nextProps.children;
}
@NoamELB
NoamELB / ShouldNotUpdatePure.js
Last active November 22, 2017 06:52
should not update with pure component
class ShouldNotUpdate extends React.PureComponent {
constructor(props) {
super(props);
this.counter = 0;
}
render() {
return `I should be rendered only 1 time. actual times rendered: ${++this.counter}`;
}
}
@NoamELB
NoamELB / updateHeightRAF.js
Last active March 29, 2019 14:55
update height with request animation frame
updateHeight(isOpen) {
this.lastRAF && cancelAnimationFrame(this.lastRAF);
if (isOpen) {
this.lastRAF = requestAnimationFrame(() => {
// read:
const height =`${this.contentEl.scrollHeight}px`;
this.lastRAF = requestAnimationFrame(() => {
// write in a different frame:
this.containerEl.style.height = height;
this.lastRAF = null;
<Tabs>
<Tab value="banana" header="Banana Header">Banana</Tab>
<Tab value="apple" header="Apple Header">Apple</Tab>
</Tabs>
@NoamELB
NoamELB / Tabs1.js
Last active December 7, 2017 15:16
getHeader(tabs) {
return tabs.map((tab, i) => {
const style = this.isSelected(tab) ? activeTabHeaderStyle : tabHeaderStyle;
return (
<span
key={tab.props.value}
onClick={e => this.selectTab(e, tab.props.value)}
style={i === 0 ? style : Object.assign({}, style, sideHeaderStyle)}
>
{tab.props.header}
isSelected(tab) {
return tab.props.value === this.state.value;
}