Add support for first line number setting (#849)

* Add support for first line number setting

* Set min value to 0

* Add number types

* add label and width settings to Input

* use Input component instead of Text

* remove unused types

* first-row -> first-line-number-row

* more .row into global stylesheet
main
Andrew Dassonville 5 years ago committed by repo-ranger[bot]
parent d5fd308828
commit 830442c64a

@ -143,6 +143,7 @@ class Carbon extends React.PureComponent {
const options = { const options = {
lineNumbers: config.lineNumbers, lineNumbers: config.lineNumbers,
firstLineNumber: config.firstLineNumber,
mode: languageMode || 'plaintext', mode: languageMode || 'plaintext',
theme: config.theme, theme: config.theme,
scrollBarStyle: null, scrollBarStyle: null,

@ -2,13 +2,15 @@ import React from 'react'
import { COLORS } from '../lib/constants' import { COLORS } from '../lib/constants'
const Input = React.forwardRef(({ color = COLORS.SECONDARY, align = 'right', ...props }, ref) => ( const Input = React.forwardRef(
({ color = COLORS.SECONDARY, align = 'right', width = '100%', label, ...props }, ref) => (
<React.Fragment> <React.Fragment>
{label && <label>{label}</label>}
<input ref={ref} {...props} /> <input ref={ref} {...props} />
<style jsx> <style jsx>
{` {`
input { input {
width: 100%; width: ${width};
font-size: 12px; font-size: 12px;
color: ${color}; color: ${color};
background: transparent; background: transparent;
@ -32,9 +34,16 @@ const Input = React.forwardRef(({ color = COLORS.SECONDARY, align = 'right', ...
input[type='file']:focus { input[type='file']:focus {
outline: initial; outline: initial;
} }
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
`} `}
</style> </style>
</React.Fragment> </React.Fragment>
)) )
)
export default Input export default Input

@ -4,6 +4,7 @@ import omitBy from 'lodash.omitby'
import ThemeSelect from './ThemeSelect' import ThemeSelect from './ThemeSelect'
import FontSelect from './FontSelect' import FontSelect from './FontSelect'
import Slider from './Slider' import Slider from './Slider'
import Input from './Input'
import Toggle from './Toggle' import Toggle from './Toggle'
import Popout, { managePopout } from './Popout' import Popout, { managePopout } from './Popout'
import Button from './Button' import Button from './Button'
@ -24,6 +25,7 @@ const WindowSettings = React.memo(
dropShadowOffsetY, dropShadowOffsetY,
windowControls, windowControls,
lineNumbers, lineNumbers,
firstLineNumber,
widthAdjustment, widthAdjustment,
watermark, watermark,
onWidthChanging, onWidthChanging,
@ -79,6 +81,18 @@ const WindowSettings = React.memo(
enabled={lineNumbers} enabled={lineNumbers}
onChange={onChange.bind(null, 'lineNumbers')} onChange={onChange.bind(null, 'lineNumbers')}
/> />
{lineNumbers && (
<div className="row settings-row first-line-number-row">
<Input
label="First line number"
type="number"
value={firstLineNumber}
min={0}
onChange={e => onChange('firstLineNumber', Number(e.target.value))}
width="50%"
/>
</div>
)}
<Toggle <Toggle
label="Auto-adjust width" label="Auto-adjust width"
enabled={widthAdjustment} enabled={widthAdjustment}
@ -87,10 +101,6 @@ const WindowSettings = React.memo(
<Toggle label="Watermark" enabled={watermark} onChange={onChange.bind(null, 'watermark')} /> <Toggle label="Watermark" enabled={watermark} onChange={onChange.bind(null, 'watermark')} />
<style jsx> <style jsx>
{` {`
.row {
display: flex;
}
.row > :global(div:first-child) { .row > :global(div:first-child) {
border-right: 1px solid ${COLORS.SECONDARY}; border-right: 1px solid ${COLORS.SECONDARY};
} }
@ -99,6 +109,14 @@ const WindowSettings = React.memo(
.drop-shadow-options :global(label) { .drop-shadow-options :global(label) {
opacity: 0.5; opacity: 0.5;
} }
.settings-content :global(.settings-row:focus-within) {
outline: -webkit-focus-ring-color auto 5px;
}
.first-line-number-row {
padding: 8px 12px 8px 8px;
}
`} `}
</style> </style>
</div> </div>
@ -184,7 +202,6 @@ const MiscSettings = React.memo(({ format, reset, applyPreset, settings }) => {
<style jsx> <style jsx>
{` {`
.row { .row {
display: flex;
flex: 1; flex: 1;
} }
.settings-content { .settings-content {
@ -365,6 +382,7 @@ class Settings extends React.PureComponent {
dropShadowOffsetY={this.props.dropShadowOffsetY} dropShadowOffsetY={this.props.dropShadowOffsetY}
windowControls={this.props.windowControls} windowControls={this.props.windowControls}
lineNumbers={this.props.lineNumbers} lineNumbers={this.props.lineNumbers}
firstLineNumber={this.props.firstLineNumber}
widthAdjustment={this.props.widthAdjustment} widthAdjustment={this.props.widthAdjustment}
watermark={this.props.watermark} watermark={this.props.watermark}
/> />

@ -19,7 +19,7 @@ class Slider extends React.Component {
const step = 'step' in this.props ? this.props.step : 1 const step = 'step' in this.props ? this.props.step : 1
return ( return (
<div className="slider"> <div className="slider settings-row">
<div <div
className="slider-bg" className="slider-bg"
style={{ style={{
@ -48,10 +48,6 @@ class Slider extends React.Component {
user-select: none; user-select: none;
} }
.slider:focus-within {
outline: -webkit-focus-ring-color auto 5px;
}
.slider:last-of-type { .slider:last-of-type {
border-bottom: 0; border-bottom: 0;
} }

@ -154,7 +154,6 @@ const ThemeCreate = ({
} }
.row { .row {
display: flex;
flex: 1; flex: 1;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;

@ -214,6 +214,10 @@ export default () => (
left: -10%; left: -10%;
} }
.row {
display: flex;
}
/* include just until we have a keyboard navigation style system */ /* include just until we have a keyboard navigation style system */
[role='button']:focus { [role='button']:focus {
outline: none; outline: none;

@ -1049,6 +1049,7 @@ export const DEFAULT_SETTINGS = {
windowControls: true, windowControls: true,
widthAdjustment: true, widthAdjustment: true,
lineNumbers: false, lineNumbers: false,
firstLineNumber: 1,
exportSize: '2x', exportSize: '2x',
watermark: false, watermark: false,
squaredImage: false, squaredImage: false,

@ -11,6 +11,11 @@ const mapper = new Morph({
if (v === 'false') return false if (v === 'false') return false
return Boolean(v) return Boolean(v)
}, },
int: v => {
const integer = parseInt(v)
if (isNaN(integer)) return undefined
return integer
},
parse: v => { parse: v => {
try { try {
const x = JSON.parse(v) const x = JSON.parse(v)
@ -56,6 +61,7 @@ const readMappings = [
{ field: 'pv:paddingVertical' }, { field: 'pv:paddingVertical' },
{ field: 'ph:paddingHorizontal' }, { field: 'ph:paddingHorizontal' },
{ field: 'ln:lineNumbers', type: 'bool' }, { field: 'ln:lineNumbers', type: 'bool' },
{ field: 'fl:firstLineNumber', type: 'int' },
{ field: 'fm:fontFamily' }, { field: 'fm:fontFamily' },
{ field: 'fs:fontSize' }, { field: 'fs:fontSize' },
{ field: 'lh:lineHeight' }, { field: 'lh:lineHeight' },
@ -82,6 +88,7 @@ const writeMappings = [
{ field: 'paddingVertical:pv' }, { field: 'paddingVertical:pv' },
{ field: 'paddingHorizontal:ph' }, { field: 'paddingHorizontal:ph' },
{ field: 'lineNumbers:ln', type: 'bool' }, { field: 'lineNumbers:ln', type: 'bool' },
{ field: 'firstLineNumber:fl', type: 'int' },
{ field: 'fontFamily:fm' }, { field: 'fontFamily:fm' },
{ field: 'fontSize:fs' }, { field: 'fontSize:fs' },
{ field: 'lineHeight:lh' }, { field: 'lineHeight:lh' },

Loading…
Cancel
Save