-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #776 from streamich/peritext-rendering-surface-inline
Peritext rendering surface inline element improvements
- Loading branch information
Showing
38 changed files
with
1,355 additions
and
96 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 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
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
151 changes: 151 additions & 0 deletions
151
src/json-crdt-peritext-ui/components/BasicButton/index.tsx
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,151 @@ | ||
// biome-ignore lint: React is used for JSX | ||
import * as React from 'react'; | ||
import {rule, lightTheme as theme, useRule, useTheme} from 'nano-theme'; | ||
import {Link} from 'nice-ui/lib/1-inline/Link'; | ||
import {Ripple} from 'nice-ui/lib/misc/Ripple'; | ||
|
||
export const blockClass = rule({ | ||
...theme.font.ui1.mid, | ||
fz: '14px', | ||
cur: 'pointer', | ||
us: 'none', | ||
trs: 'background .12s ease-in 0s, opacity .12s ease-in 0s', | ||
d: 'inline-flex', | ||
ai: 'center', | ||
jc: 'center', | ||
fls: 0, | ||
bdrad: '3px', | ||
bg: 'transparent', | ||
bd: 0, | ||
mr: 0, | ||
pd: 0, | ||
out: 0, | ||
ov: 'visible', | ||
'&:hover': { | ||
bxsh: 'none', | ||
}, | ||
'&:active': { | ||
bxsh: 'none', | ||
}, | ||
}); | ||
|
||
const handleDragStart = (e: React.MouseEvent) => e.preventDefault(); | ||
|
||
export interface BasicButtonProps extends React.AllHTMLAttributes<any> { | ||
to?: string; | ||
border?: boolean; | ||
fill?: boolean; | ||
size?: number; | ||
width?: 'auto' | number | string; | ||
height?: number | string; | ||
round?: boolean; | ||
title?: string; | ||
positive?: boolean; | ||
noOutline?: boolean; | ||
transparent?: boolean; | ||
compact?: boolean; | ||
spacious?: boolean; | ||
radius?: number | string; | ||
onClick?: React.MouseEventHandler; | ||
} | ||
|
||
export const BasicButton: React.FC<BasicButtonProps> = ({ | ||
to, | ||
border, | ||
fill, | ||
size = 24, | ||
width = size, | ||
height = size, | ||
round, | ||
title, | ||
positive, | ||
noOutline, | ||
transparent, | ||
onClick, | ||
children, | ||
compact, | ||
spacious, | ||
radius, | ||
className = '', | ||
...rest | ||
}) => { | ||
const theme = useTheme(); | ||
const {isLight} = theme; | ||
const bgFactor = isLight ? 1 : 1.1; | ||
|
||
const dynamicBlockClass = useRule(({g}) => ({ | ||
// col: g(0.2), | ||
// svg: { | ||
// fill: g(0.5), | ||
// col: g(0.5), | ||
// }, | ||
'&:hover': { | ||
// col: g(0.2), | ||
bg: g(0, 0.08 * bgFactor), | ||
}, | ||
'&:active': { | ||
bg: g(0, 0.16 * bgFactor), | ||
}, | ||
})); | ||
|
||
const fillBlockClass = useRule(({g}) => ({ | ||
bg: transparent ? 'transparent' : g(0, 0.04 * bgFactor), | ||
'&:hover': { | ||
bg: g(0, 0.08 * bgFactor), | ||
}, | ||
'&:active': { | ||
bg: g(0, 0.16 * bgFactor), | ||
}, | ||
})); | ||
|
||
const borderClass = useRule(({g}) => ({ | ||
bd: `1px solid ${g(0, 0.16 * bgFactor)}`, | ||
boxShadow: `0 0 2px ${g(0, 0.04 * bgFactor)}`, | ||
})); | ||
|
||
const style: React.CSSProperties = { | ||
height, | ||
}; | ||
|
||
style.width = width; | ||
if (typeof width !== 'number') { | ||
if (spacious) { | ||
style.padding = '8px 16px'; | ||
} else { | ||
style.paddingLeft = compact ? 8 : 16; | ||
style.paddingRight = compact ? 8 : 16; | ||
} | ||
} | ||
|
||
if (round) { | ||
style.borderRadius = '50%'; | ||
} | ||
|
||
if (noOutline) { | ||
style.boxShadow = 'none'; | ||
} | ||
|
||
if (radius !== undefined) { | ||
style.borderRadius = radius; | ||
} | ||
|
||
return ( | ||
<Ripple ms={1_500} color={positive ? theme.color.sem.positive[0] : theme.g(0, 0.08)}> | ||
<Link | ||
{...rest} | ||
a={!!to} | ||
className={ | ||
className + blockClass + dynamicBlockClass + (border ? borderClass : '') + (fill ? fillBlockClass : '') | ||
} | ||
style={style} | ||
title={title} | ||
onClick={to ? undefined : onClick} | ||
onDragStart={handleDragStart} | ||
to={to} | ||
data-testid="BasicButton" | ||
> | ||
{children} | ||
</Link> | ||
</Ripple> | ||
); | ||
}; |
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,22 @@ | ||
import * as React from 'react'; | ||
import {RenderCaret} from './RenderCaret'; | ||
import {RenderFocus} from './RenderFocus'; | ||
import {RenderAnchor} from './RenderAnchor'; | ||
import {RenderInline} from './RenderInline'; | ||
import {RenderPeritext} from './RenderPeritext'; | ||
import type {PeritextPlugin} from '../../react/types'; | ||
|
||
const h = React.createElement; | ||
|
||
/** | ||
* Plugin which renders the main cursor and all other current user local | ||
* cursors. | ||
*/ | ||
export class CursorPlugin implements PeritextPlugin { | ||
public readonly caret: PeritextPlugin['caret'] = (props, children) => h(RenderCaret, <any>props, children); | ||
public readonly focus: PeritextPlugin['focus'] = (props, children) => h(RenderFocus, <any>props, children); | ||
public readonly anchor: PeritextPlugin['anchor'] = (props, children) => h(RenderAnchor, <any>props, children); | ||
public readonly inline: PeritextPlugin['inline'] = (props, children) => h(RenderInline, props as any, children); | ||
public readonly peritext: PeritextPlugin['peritext'] = (props, children, ctx) => | ||
h(RenderPeritext, {...props, children, ctx, plugin: this}); | ||
} |
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
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
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 |
---|---|---|
@@ -1,21 +1 @@ | ||
import * as React from 'react'; | ||
import {RenderCaret} from './RenderCaret'; | ||
import {RenderFocus} from './RenderFocus'; | ||
import {RenderAnchor} from './RenderAnchor'; | ||
import {RenderInline} from './RenderInline'; | ||
import {RenderPeritext} from './RenderPeritext'; | ||
import type {PeritextPlugin} from '../../react/types'; | ||
|
||
const h = React.createElement; | ||
|
||
/** | ||
* Plugin which renders the main cursor and all other current user local | ||
* cursors. | ||
*/ | ||
export const cursorPlugin: PeritextPlugin = { | ||
caret: (props, children) => h(RenderCaret, <any>props, children), | ||
focus: (props, children) => h(RenderFocus, <any>props, children), | ||
anchor: (props, children) => h(RenderAnchor, <any>props, children), | ||
inline: (props, children) => h(RenderInline, props as any, children), | ||
peritext: (props, children, ctx) => h(RenderPeritext, {...props, children, ctx}), | ||
}; | ||
export {CursorPlugin} from './CursorPlugin'; |
Oops, something went wrong.