Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds live page preview on hover :) #52

Merged
merged 34 commits into from May 17, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e1e5c57
adds page preview on hover :)
May 10, 2020
9c06df6
disable preview on toggle
May 11, 2020
b9ee395
use popper for positioning
May 12, 2020
c16e1ba
remove popper if item is removed from dom
May 12, 2020
9c60b20
set scrollTop to 0 for next hover
May 12, 2020
fc3a3d3
support page-ref-tag
May 12, 2020
8a7183e
- disable by default;
May 15, 2020
62d7a67
add warning tooltip, uses react-tooltip-popper
May 15, 2020
53f03d2
rename warningTooltip -> warning
May 16, 2020
db31638
fix: reducer
May 16, 2020
dcfc937
refactor to PreviewIframe class
May 16, 2020
806203d
refactor Tooltip
May 16, 2020
79d4dca
revert manifest.json
May 16, 2020
282f915
clear instance on disable
May 16, 2020
3129b48
Merge commit 'c9593ccce94a31f18bc60b2acbfac5f10b7b7a5e' into live-pre…
May 16, 2020
e29481d
chore: private functions
May 16, 2020
6740221
move initial state to function
May 16, 2020
99338a9
add comment for hack
May 16, 2020
02c9db7
use daily notes page for first load
May 16, 2020
cece075
rename function
May 16, 2020
eabd431
Merge commit 'a955330ee4859b3c7dc88b1bf3bb8cbd0c845aa7' into live-pre…
May 16, 2020
bb08eae
review changes
May 16, 2020
ea574cd
fix comment
May 16, 2020
53459da
fix: condition
May 16, 2020
b64069e
remove log
May 16, 2020
cc7e463
fix: mouse handling
May 16, 2020
13af95d
remove body check
May 16, 2020
5a8d720
review
May 16, 2020
9afd28e
fix: create iframe in constructor,
May 17, 2020
7210520
fix: navigation function
May 17, 2020
73004cf
fix: type
May 17, 2020
f01d18e
Merge remote-tracking branch 'origin/master' into live-preview
May 17, 2020
caff0e7
move live-preview file, add to features
May 17, 2020
aa798b7
remove exisitingIframe check,
May 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
459 changes: 446 additions & 13 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -16,11 +16,13 @@
},
"license": "MIT",
"dependencies": {
"@popperjs/core": "^2.4.0",
"chrono-node": "^1.4.2",
"dateformat": "^3.0.3",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-hotkeys": "^2.0.0",
"react-popper-tooltip": "^2.11.1",
"react-redux": "^7.1.3",
"redux": "^4.0.5",
"styled-components": "^5.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/manifest.json
Expand Up @@ -41,6 +41,7 @@
"inc-dec-value.js",
"dispatcher.js",
"block-manipulation.js",
"live-preview.js",
"custom-css.js",
"fuzzy_date.js",
"create-block-demo.js"
Expand Down
51 changes: 51 additions & 0 deletions src/ts/components/Tooltip.tsx
@@ -0,0 +1,51 @@
import React from 'react'
import TooltipTrigger, {ChildrenArg, TooltipArg} from 'react-popper-tooltip'
import styled from 'styled-components'

type Props = {
children: any
tooltip?: string
}
const StyledTooltipContent = styled('div')`
max-width: 140px;
background-color: #111;
color: white;
padding: 10px;
`
function renderTooltipContent(tooltip: string) {
return ({tooltipRef, getTooltipProps}: TooltipArg) => (
<StyledTooltipContent
{...getTooltipProps({
ref: tooltipRef,
className: 'tooltip-container',
})}
>
{tooltip}
</StyledTooltipContent>
)
}
function renderTooltipTrigger(children: any) {
return ({getTriggerProps, triggerRef}: ChildrenArg) => (
<span
{...getTriggerProps({
ref: triggerRef,
className: 'trigger',
})}
>
{children}
</span>
)
}

const Tooltip = ({children, tooltip, ...props}: Props) => {
if (!tooltip) {
return children
}
return (
<TooltipTrigger {...props} tooltip={renderTooltipContent(tooltip)}>
{renderTooltipTrigger(children)}
</TooltipTrigger>
)
}

export default Tooltip
41 changes: 41 additions & 0 deletions src/ts/components/WarningIcon.tsx
@@ -0,0 +1,41 @@
import * as React from 'react'
import styled from 'styled-components'
import Tooltip from './Tooltip'

type WarningIconProps = {
warning?: string
}
const IconWrap = styled('div')`
display: flex;
align-items: center;
justify-content: center;
height: 20px;
background-color: rgba(255, 165, 0, 0.1);
width: 20px;
border-radius: 4px;

&:hover {
background-color: rgba(255, 165, 0, 0.25);
}
`

const WarningIconSvg = (props: {fill: string}) => {
return (
<svg width={'12px'} viewBox="0 0 640 640" {...props}>
<title />
<path d="M93.76 546.24C33.487 487.969-3.932 406.389-3.932 316.067c0-176.731 143.269-320 320-320 90.321 0 171.902 37.42 230.086 97.602l.086.09c55.578 57.487 89.828 135.897 89.828 222.307 0 176.731-143.269 320-320 320-86.41 0-164.821-34.249-222.398-89.914l.09.086zM288 160v192h64V160h-64zm0 256v64h64v-64h-64z" />
</svg>
)
}
export const WarningIcon = (props: WarningIconProps) => {
if (!props.warning) {
return null
}
return (
<Tooltip tooltip={props.warning}>
<IconWrap>
<WarningIconSvg fill="orange" />
</IconWrap>
</Tooltip>
)
}
7 changes: 5 additions & 2 deletions src/ts/containers/Settings/Home.tsx
Expand Up @@ -6,6 +6,7 @@ import {setFeatureId} from '../../background/store/settings/actions'
import {Feature} from '../../utils/settings'

import {Checkbox} from '../../components/Checkbox'
import {WarningIcon} from '../../components/WarningIcon'

type HomeProps = {features: Feature[]}
export const Home = ({features}: HomeProps) => {
Expand Down Expand Up @@ -33,6 +34,7 @@ export const Home = ({features}: HomeProps) => {
<span className="title">{feature.name}</span>
<span style={{color: '#a7b6c2'}}>]]</span>
</FeatureName>
<WarningIcon warning={feature.warning} />
</FeatureNameContainer>
)

Expand Down Expand Up @@ -100,10 +102,11 @@ const FeatureListElement = styled('li')`
}
}
`

const FeatureName = styled('div')`
const FeatureName = styled('span')`
color: #137cbd;
padding: 0 0 0 2px;
font-size: 17px;
margin-right: 8px;
`

const FeatureNameContainer = styled('div')`
Expand Down
6 changes: 3 additions & 3 deletions src/ts/contentScripts/custom-css/index.tsx
Expand Up @@ -7,16 +7,16 @@ export const config: Feature = {
settings: [{type: 'large_string', id: 'css'}],
}

Settings.isActive('custom-css').then(active => {
Settings.isActive(config.id).then(active => {
if (active) {
Settings.get('custom-css', 'css').then((value: string) => {
Settings.get(config.id, 'css').then((value: string) => {
setCss(value)
})
}
})

browser.runtime.onMessage.addListener(async message => {
if (message?.featureId === 'custom-css') {
if (message?.featureId === config.id) {
setCss(message.value)
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/ts/contentScripts/features.ts
Expand Up @@ -4,6 +4,7 @@ import {config as incDec} from './inc-dec-value/index'
import {config as customCss} from './custom-css/index'
import {config as srs} from './srs/index'
import {config as blockManipulation} from './block-manipulation'
import {config as livePreview} from './live-preview'
import {config as estimate} from './estimates/index'
import {config as navigation} from './navigation/index'
import {filterAsync, mapAsync} from '../utils/async'
Expand All @@ -16,6 +17,7 @@ export const Features = {
estimate,
customCss,
navigation,
livePreview,
]),

isActive: Settings.isActive,
Expand Down