Skip to content

Commit

Permalink
feat(reader-react): adds responsive font sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
msimmer committed Jun 10, 2022
1 parent 2f760f0 commit 22e6961
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
22 changes: 5 additions & 17 deletions packages/b-ber-reader-react/src/components/Frame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class Frame extends React.Component {
}

style() {
const { fontSize } = this.props.viewerSettings

let style = {
position: 'absolute',
top: 0,
Expand All @@ -52,30 +50,20 @@ class Frame extends React.Component {
margin: 0,
padding: 0,
border: 0,
fontSize,
}

if (Viewport.isVerticallyScrolling(this.props)) {
// Mobile
style = {
...style,
WebkitOverflowScrolling: 'touch',
overflowY: 'auto',
overflowX: 'hidden',
}
style.WebkitOverflowScrolling = 'touch'
style.overflowY = 'auto'
style.overflowX = 'hidden'
} else {
// Desktop
style = {
...style,
overflow: 'hidden',
}
style.overflow = 'hidden'
}

if (isPlainObject(this.props.style)) {
style = {
...style,
...this.props.style,
}
style = { ...style, ...this.props.style }
}

return style
Expand Down
2 changes: 2 additions & 0 deletions packages/b-ber-reader-react/src/components/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Layout extends React.Component {
paddingLeft,
paddingRight,
paddingBottom,
fontSize,
} = this.props.viewerSettings

const { margin, border, boxSizing, columnFill, transform } = this.state
Expand All @@ -121,6 +122,7 @@ class Layout extends React.Component {
columns,
columnFill,
transform,
fontSize,
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/b-ber-reader-react/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const horizontalBreakpoints = new Map([
paddingRight: '15px',
paddingTop: 0,
paddingBottom: '80px', // Offset for bottom nav
fontSize: 'clamp(130%, 1.5vw, 160%)',
},
],
[
Expand All @@ -68,6 +69,7 @@ export const horizontalBreakpoints = new Map([
paddingRight: 0,
paddingTop: 0,
paddingBottom: '80px', // Offset for bottom nav
fontSize: 'clamp(130%, 1.5vw, 160%)',
},
],
[
Expand All @@ -81,6 +83,7 @@ export const horizontalBreakpoints = new Map([
paddingRight: 0,
paddingTop: 0,
paddingBottom: 0,
fontSize: '137%', // 21.92px
},
],
[
Expand All @@ -94,6 +97,7 @@ export const horizontalBreakpoints = new Map([
paddingRight: 0,
paddingTop: 0,
paddingBottom: 0,
fontSize: '137%', // 21.92px
},
],
[
Expand All @@ -107,6 +111,7 @@ export const horizontalBreakpoints = new Map([
paddingRight: 0,
paddingTop: 0,
paddingBottom: 0,
fontSize: '155%', // 24.8px
},
],
[
Expand All @@ -120,6 +125,7 @@ export const horizontalBreakpoints = new Map([
paddingRight: 0,
paddingTop: 0,
paddingBottom: 0,
fontSize: '195%', // 31.2px
},
],
])
2 changes: 2 additions & 0 deletions packages/b-ber-reader-react/src/helpers/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Viewport {
paddingRight,
paddingTop,
paddingBottom,
fontSize,
} = css

const horizontalPadding = Viewport.getHorizontalSpacing(maxWidth)
Expand All @@ -118,6 +119,7 @@ class Viewport {
paddingTop: verticalPadding + parseInt(paddingTop, 10),
paddingBottom: verticalPadding + parseInt(paddingBottom, 10),
columnGap: parseInt(columnGap, 10),
fontSize,
columns,
}

Expand Down
4 changes: 2 additions & 2 deletions packages/b-ber-reader-react/src/models/ViewerSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class ViewerSettings {

width: 0,
height: 0,
fontSize: '120%', // TODO not working, unused

// Theme settings, transition speed in ms
theme: themes.DEFAULT,
transition: transitions.SLIDE,
transitionSpeed: 400,
columns: 2,

fontSize: () => Viewport.styles().fontSize,
columnGap: () => Viewport.styles().columnGap,
paddingLeft: () => Viewport.styles().paddingLeft,
paddingRight: () => Viewport.styles().paddingRight,
Expand Down Expand Up @@ -171,7 +171,7 @@ class ViewerSettings {
}

get fontSize() {
return this.settings.fontSize
return valueOf(this.settings.fontSize)
}

set fontSize(val) {
Expand Down

0 comments on commit 22e6961

Please sign in to comment.