This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
165 changed files
with
1,611 additions
and
17,517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
trailingComma: 'all', | ||
singleQuote: true, | ||
arrowParens: 'always', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const { pipe } = require('@typographist/core'); | ||
|
||
const { toEm, toPx, toEmOrNot, hasEm, camelize } = require('../utils'); | ||
const { getNextBreakpointValue } = require('./helpers'); | ||
|
||
// normalizeBreakParams :: [String] -> String | ||
const normalizeBreakParams = (x) => camelize(String(x)); | ||
|
||
// calcMaxBreakValue :: (String | Number) -> Number | ||
const calcMaxBreakValue = (x) => toEm(parseFloat(x) - 0.02); | ||
|
||
// calcMinWidth :: Object -> [String] -> String | ||
exports.calcMinWidth = (breakpoints) => (breakpoint) => { | ||
const breakParams = normalizeBreakParams(breakpoint); | ||
|
||
return breakpoints[breakParams] | ||
? toEm(breakpoints[breakParams].value) | ||
: toEmOrNot(breakParams); | ||
}; | ||
|
||
// calcMaxWidth :: Object -> String -> String | ||
exports.calcMaxWidth = (breakpoints) => (breakpoint) => { | ||
const breakParams = normalizeBreakParams(breakpoint); | ||
|
||
if (breakpoints[breakParams]) { | ||
return pipe( | ||
getNextBreakpointValue(breakParams), | ||
calcMaxBreakValue, | ||
)(breakpoints); | ||
} | ||
|
||
if (hasEm(breakParams)) { | ||
return calcMaxBreakValue(toPx(breakParams)); | ||
} | ||
|
||
return calcMaxBreakValue(breakParams); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const { toKebabCase } = require('../utils'); | ||
|
||
// const NOT_BREAKPOINT_NAME = /^\((\w+)\).*$/g; | ||
const NOT_BREAKPOINT_NAMES = /^\((\w+(,?\w+)?)\).*$/g; | ||
const ALL_CHARACTERS_BEFORE_COLON = /^\(.+\):?/; | ||
const SPACES = /\s/g; | ||
|
||
// getOrientation :: String -> String | ||
const getOrientation = (x) => x.replace(ALL_CHARACTERS_BEFORE_COLON, ''); | ||
|
||
// getBreakpointValues :: String -> String | ||
const getBreakpointValues = (params) => | ||
params | ||
.replace(SPACES, '') | ||
.replace(NOT_BREAKPOINT_NAMES, '$1') | ||
.split(','); | ||
|
||
// makeBreakpointList :: Object -> [String] | ||
const makeBreakpointList = (x) => | ||
Object.keys(x) | ||
.map(toKebabCase) | ||
.join(', '); | ||
|
||
// withMinWidth :: String -> String | ||
const withMinWidth = (x) => `(min-width: ${x})`; | ||
|
||
// withMaxMedia :: String -> String | ||
const withMaxWidth = (x) => `(max-width: ${x})`; | ||
|
||
// withMinAndMaxWidth :: (String, String) -> String | ||
const withMinAndMaxWidth = (min, max) => | ||
`(min-width: ${min}) and (max-width: ${max})`; | ||
|
||
// withOrientationOrNot :: String -> String -> String | ||
const withOrientationOrNot = (orientation) => (params) => | ||
orientation ? `${params} and (orientation: ${orientation})` : params; | ||
|
||
// antecedentBreakName :: Object -> String | ||
const antecedentBreakName = (x) => Object.keys(x)[Object.keys(x).length - 2]; | ||
|
||
// getlastBreakIndex :: Object -> Number | ||
const getlastBreakIndex = (x) => Object.keys(x).length - 1; | ||
|
||
// getCurrentIndex :: (String, Object) -> Number | ||
const getCurrentIndex = (name, breakpoints) => | ||
Object.keys(breakpoints).indexOf(name); | ||
|
||
// getNextBreakpointValue :: String -> Object -> String | ||
const getNextBreakpointValue = (name) => (breakpoints) => { | ||
const currentIndex = getCurrentIndex(name, breakpoints); | ||
const nextBreakpointName = Object.keys(breakpoints)[currentIndex + 1]; | ||
|
||
return breakpoints[nextBreakpointName].value; | ||
}; | ||
|
||
module.exports = { | ||
getOrientation, | ||
getBreakpointValues, | ||
makeBreakpointList, | ||
withMinWidth, | ||
withMaxWidth, | ||
withMinAndMaxWidth, | ||
withOrientationOrNot, | ||
antecedentBreakName, | ||
getlastBreakIndex, | ||
getCurrentIndex, | ||
getNextBreakpointValue, | ||
}; |
Oops, something went wrong.