Skip to content

Commit

Permalink
added Time settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kholmogorov27 committed Mar 10, 2023
1 parent 3ddb6e3 commit ce25dae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,15 @@ const template = {
),
pagination: new types.Switch(false),
arrows: new types.Switch(true),
drag: new types.Switch(true)
drag: new types.Switch(true),
time: {
fontSize: new types.Range(
1,
{ min: 0.1, max: 10, step: 0.1 },
{ format: '{@}em' }
),
format: new types.Input('h:MM')
}
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/components/Time/Time.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { useEffect, useState } from 'react'
import { useContext, useEffect, useState } from 'react'
import { SettingsContext } from '../../contexts/Settings'
import dateFormat from 'dateformat'
import classes from './Time.module.css'

function Time() {
/* settings */
const settings = useContext(SettingsContext)

const fontSize = settings.menu.time.fontSize
const format = settings.menu.time.format

const [time, setTime] = useState(new Date())

useEffect(() => {
Expand All @@ -15,9 +22,13 @@ function Time() {
return () => clearTimeout(window[timerGlobalRef])
}, [])

const variables = {
'--font-size': fontSize + 'em'
}

return (
<div className={classes['time']}>
{dateFormat(time, 'h:MM')}
<div className={classes['time']} style={variables}>
{dateFormat(time, format)}
</div>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Time/Time.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.time {
color: var(--time);
font-size: var(--font-size);
}

0 comments on commit ce25dae

Please sign in to comment.