Skip to content

Instantly share code, notes, and snippets.

View jm2242's full-sized avatar

Jonathan Mares jm2242

View GitHub Profile
@jm2242
jm2242 / constants.json
Last active February 20, 2018 20:25
Constants file
{
"columnIconsSize": "26px",
"columnIconsMargin": "6px",
"columnNameFont": "normal normal 300 16px Helvetica"
}
@jm2242
jm2242 / decode-styles.js
Created February 20, 2018 20:27
Decode a JSON style object
/**
* Decode a JSON object of style key/value pairs
* Currently only cleans out the 'px' from values
* and ignores styles with spaces to allow for fonts
* @param {Object} styles - styles to decode
* @returns {Object} - decoded key/value pairs
*/
export const decodeStyles = styles => {
const decodedStyles = {}
Object.entries(styles).forEach(
@jm2242
jm2242 / handle-styles.jsx
Created February 20, 2018 20:28
Handle Styles in React component
// — — — — — BEGIN handle styles — — — — — — — //
// count the number of buttons we want to show
const numberOfButtons = [canAddColumns, canHideColumns, canRemoveColumns, canSearch, canSort].reduce(
(acc, showButton) => showButton ? acc+1 : acc,
0
)
const totalColumnIconsWidth = numberOfButtons * (sheetsVariables.columnIconsSize + sheetsVariables.columnIconsMargin)
// styles object
const headerCellStyles = {
columnIcons: encodeStyles({
@jm2242
jm2242 / encode-styles.jsx
Created February 20, 2018 20:28
Encode Styles object
/**
* Encode an object of styles for the browser to understand
* @param {Object} styles - styles to decode
* @returns {Object} - Something
*/
export const encodeStyles = styles => {
const encodedStyles = {}
Object.entries(styles).forEach(
([key, value]) => {
// add the pixels back in if the value is a number
@jm2242
jm2242 / pass-styles.jsx
Created February 20, 2018 22:13
Pass in Styles
render() {
...
<div className=”column-icons” style={headerCellStyles.columnIcons}>
{ canHideColumns && renderHideColumnsTrigger() }
{ canSort && renderSortingIndicator() }
{ canSearch && renderSearchTrigger() }
{ canRemoveColumns && <RemoveColumnButton /> }
{ canAddColumns && <AddColumnButton }
...
@jm2242
jm2242 / keybase.md
Created December 25, 2018 02:54
Keybase Proof

Keybase proof

I hereby claim:

  • I am jm2242 on github.
  • I am jmares (https://keybase.io/jmares) on keybase.
  • I have a public key ASBiCanwF9ll52krTUdbO2tnUIbgpF4SrJTBUoy72c-pQgo

To claim this, I am signing this object: