add title attr to text text links (#1228)

* add title attr to text text links

* Revert "add title attr to text text links"

This reverts commit c028cd184efd3b2788d8f46134eecf521e5d7b07.

* use css tooltips

* add to expanded post state

* handle theming

* add to bskyweb
zio/stable
Eric Bailey 2023-08-22 13:04:17 -05:00 committed by GitHub
parent 16b265a861
commit 548ec6c82d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 166 additions and 22 deletions

View File

@ -16,6 +16,7 @@ module.exports = {
'*.lock', '*.lock',
'.husky', '.husky',
'patches', 'patches',
'*.html',
], ],
overrides: [ overrides: [
{ {

View File

@ -39,6 +39,32 @@
height: calc(100% + env(safe-area-inset-top)); height: calc(100% + env(safe-area-inset-top));
} }
/* Color theming */
:root {
--text: black;
--background: white;
--backgroundLight: #F3F3F8;
}
html.colorMode--dark {
--text: white;
--background: black;
--backgroundLight: #26272D;
}
@media (prefers-color-scheme: light) {
html.colorMode--system {
--text: black;
--background: white;
--backgroundLight: #F3F3F8;
}
}
@media (prefers-color-scheme: dark) {
html.colorMode--system {
--text: white;
--background: black;
--backgroundLight: #26272D;
}
}
body { body {
display: flex; display: flex;
/* Allows you to scroll below the viewport; default value is visible */ /* Allows you to scroll below the viewport; default value is visible */
@ -49,12 +75,6 @@
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
-ms-overflow-style: scrollbar; -ms-overflow-style: scrollbar;
} }
/* Enable for apps that support dark-theme */
/*@media (prefers-color-scheme: dark) {
body {
background-color: black;
}
}*/
/* Remove default link styling */ /* Remove default link styling */
a { a {
@ -109,6 +129,44 @@
.tippy-content .items { .tippy-content .items {
width: fit-content; width: fit-content;
} }
/* Tooltips */
[data-tooltip] {
position: relative;
z-index: 10;
}
[data-tooltip]::after {
content: attr(data-tooltip);
display: none;
position: absolute;
bottom: 0;
left: 50%;
transform: translateY(100%) translateY(8px) translateX(-50%);
padding: 4px 10px;
border-radius: 10px;
background: var(--backgroundLight);
color: var(--text);
text-align: center;
white-space: nowrap;
font-size: 12px;
z-index: 10;
}
[data-tooltip]::before {
content: '';
display: none;
position: absolute;
border-bottom: 6px solid var(--backgroundLight);
border-left: 6px solid transparent;
border-right: 6px solid transparent;
bottom: 0;
left: 50%;
transform: translateY(100%) translateY(2px) translateX(-50%);
z-index: 10;
}
[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
display:block;
}
</style> </style>
{% include "scripts.html" %} {% include "scripts.html" %}
<link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">

View File

@ -267,13 +267,20 @@ export class ShellUiModel {
hydrate(v: unknown) { hydrate(v: unknown) {
if (isObj(v)) { if (isObj(v)) {
if (hasProp(v, 'colorMode') && isColorMode(v.colorMode)) { if (hasProp(v, 'colorMode') && isColorMode(v.colorMode)) {
this.colorMode = v.colorMode this.setColorMode(v.colorMode)
} }
} }
} }
setColorMode(mode: ColorMode) { setColorMode(mode: ColorMode) {
this.colorMode = mode this.colorMode = mode
if (typeof window !== 'undefined') {
const html = window.document.documentElement
// remove any other color mode classes
html.className = html.className.replace(/colorMode--\w+/g, '')
html.classList.add(`colorMode--${mode}`)
}
} }
setMinimalShellMode(v: boolean) { setMinimalShellMode(v: boolean) {

View File

@ -193,7 +193,8 @@ export const PostThreadItem = observer(function PostThreadItem({
/> />
</View> </View>
<View style={styles.layoutContent}> <View style={styles.layoutContent}>
<View style={[styles.meta, styles.metaExpandedLine1]}> <View
style={[styles.meta, styles.metaExpandedLine1, {zIndex: 1}]}>
<View style={[s.flexRow]}> <View style={[s.flexRow]}>
<Link <Link
style={styles.metaItem} style={styles.metaItem}
@ -210,12 +211,16 @@ export const PostThreadItem = observer(function PostThreadItem({
)} )}
</Text> </Text>
</Link> </Link>
<Text type="md" style={[styles.metaItem, pal.textLight]}>
&middot;&nbsp;
<TimeElapsed timestamp={item.post.indexedAt}> <TimeElapsed timestamp={item.post.indexedAt}>
{({timeElapsed}) => <>{timeElapsed}</>} {({timeElapsed}) => (
</TimeElapsed> <Text
type="md"
style={[styles.metaItem, pal.textLight]}
title={niceDate(item.post.indexedAt)}>
&middot;&nbsp;{timeElapsed}
</Text> </Text>
)}
</TimeElapsed>
</View> </View>
</View> </View>
<View style={styles.meta}> <View style={styles.meta}>

View File

@ -135,6 +135,7 @@ export const TextLink = observer(function TextLink({
numberOfLines, numberOfLines,
lineHeight, lineHeight,
dataSet, dataSet,
title,
}: { }: {
testID?: string testID?: string
type?: TypographyVariant type?: TypographyVariant
@ -144,6 +145,7 @@ export const TextLink = observer(function TextLink({
numberOfLines?: number numberOfLines?: number
lineHeight?: number lineHeight?: number
dataSet?: any dataSet?: any
title?: string
} & TextProps) { } & TextProps) {
const {...props} = useLinkProps({to: sanitizeUrl(href)}) const {...props} = useLinkProps({to: sanitizeUrl(href)})
const store = useStores() const store = useStores()
@ -173,8 +175,8 @@ export const TextLink = observer(function TextLink({
style={style} style={style}
numberOfLines={numberOfLines} numberOfLines={numberOfLines}
lineHeight={lineHeight} lineHeight={lineHeight}
// @ts-ignore web only -prf
dataSet={dataSet} dataSet={dataSet}
title={title}
// @ts-ignore web only -prf // @ts-ignore web only -prf
hrefAttrs={hrefAttrs} // hack to get open in new tab to work on safari. without this, safari will open in a new window hrefAttrs={hrefAttrs} // hack to get open in new tab to work on safari. without this, safari will open in a new window
{...props}> {...props}>
@ -197,6 +199,7 @@ interface DesktopWebTextLinkProps extends TextProps {
accessible?: boolean accessible?: boolean
accessibilityLabel?: string accessibilityLabel?: string
accessibilityHint?: string accessibilityHint?: string
title?: string
} }
export const DesktopWebTextLink = observer(function DesktopWebTextLink({ export const DesktopWebTextLink = observer(function DesktopWebTextLink({
testID, testID,
@ -218,6 +221,7 @@ export const DesktopWebTextLink = observer(function DesktopWebTextLink({
text={text} text={text}
numberOfLines={numberOfLines} numberOfLines={numberOfLines}
lineHeight={lineHeight} lineHeight={lineHeight}
title={props.title}
{...props} {...props}
/> />
) )
@ -229,6 +233,7 @@ export const DesktopWebTextLink = observer(function DesktopWebTextLink({
style={style} style={style}
numberOfLines={numberOfLines} numberOfLines={numberOfLines}
lineHeight={lineHeight} lineHeight={lineHeight}
title={props.title}
{...props}> {...props}>
{text} {text}
</Text> </Text>

View File

@ -79,6 +79,7 @@ export const PostMeta = observer(function (opts: PostMetaOpts) {
lineHeight={1.2} lineHeight={1.2}
text={timeElapsed} text={timeElapsed}
accessibilityLabel={niceDate(opts.timestamp)} accessibilityLabel={niceDate(opts.timestamp)}
title={niceDate(opts.timestamp)}
accessibilityHint="" accessibilityHint=""
href={opts.postHref} href={opts.postHref}
/> />
@ -94,6 +95,7 @@ const styles = StyleSheet.create({
alignItems: isAndroid ? 'center' : 'baseline', alignItems: isAndroid ? 'center' : 'baseline',
paddingBottom: 2, paddingBottom: 2,
gap: 4, gap: 4,
zIndex: 1,
}, },
avatar: { avatar: {
alignSelf: 'center', alignSelf: 'center',

View File

@ -6,6 +6,8 @@ import {useTheme, TypographyVariant} from 'lib/ThemeContext'
export type CustomTextProps = TextProps & { export type CustomTextProps = TextProps & {
type?: TypographyVariant type?: TypographyVariant
lineHeight?: number lineHeight?: number
title?: string
dataSet?: Record<string, string | number>
} }
export function Text({ export function Text({
@ -13,13 +15,19 @@ export function Text({
children, children,
lineHeight, lineHeight,
style, style,
title,
dataSet,
...props ...props
}: React.PropsWithChildren<CustomTextProps>) { }: React.PropsWithChildren<CustomTextProps>) {
const theme = useTheme() const theme = useTheme()
const typography = theme.typography[type] const typography = theme.typography[type]
const lineHeightStyle = lineHeight ? lh(theme, type, lineHeight) : undefined const lineHeightStyle = lineHeight ? lh(theme, type, lineHeight) : undefined
return ( return (
<RNText style={[s.black, typography, lineHeightStyle, style]} {...props}> <RNText
style={[s.black, typography, lineHeightStyle, style]}
// @ts-ignore web only -esb
dataSet={Object.assign({tooltip: title}, dataSet || {})}
{...props}>
{children} {children}
</RNText> </RNText>
) )

View File

@ -43,6 +43,32 @@
height: calc(100% + env(safe-area-inset-top)); height: calc(100% + env(safe-area-inset-top));
} }
/* Color theming */
:root {
--text: black;
--background: white;
--backgroundLight: #F3F3F8;
}
html.colorMode--dark {
--text: white;
--background: black;
--backgroundLight: #26272D;
}
@media (prefers-color-scheme: light) {
html.colorMode--system {
--text: black;
--background: white;
--backgroundLight: #F3F3F8;
}
}
@media (prefers-color-scheme: dark) {
html.colorMode--system {
--text: white;
--background: black;
--backgroundLight: #26272D;
}
}
body { body {
display: flex; display: flex;
/* Allows you to scroll below the viewport; default value is visible */ /* Allows you to scroll below the viewport; default value is visible */
@ -53,12 +79,6 @@
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
-ms-overflow-style: scrollbar; -ms-overflow-style: scrollbar;
} }
/* Enable for apps that support dark-theme */
/*@media (prefers-color-scheme: dark) {
body {
background-color: black;
}
}*/
/* Remove default link styling */ /* Remove default link styling */
a { a {
@ -113,6 +133,44 @@
.tippy-content .items { .tippy-content .items {
width: fit-content; width: fit-content;
} }
/* Tooltips */
[data-tooltip] {
position: relative;
z-index: 10;
}
[data-tooltip]::after {
content: attr(data-tooltip);
display: none;
position: absolute;
bottom: 0;
left: 50%;
transform: translateY(100%) translateY(8px) translateX(-50%);
padding: 4px 10px;
border-radius: 10px;
background: var(--backgroundLight);
color: var(--text);
text-align: center;
white-space: nowrap;
font-size: 12px;
z-index: 10;
}
[data-tooltip]::before {
content: '';
display: none;
position: absolute;
border-bottom: 6px solid var(--backgroundLight);
border-left: 6px solid transparent;
border-right: 6px solid transparent;
bottom: 0;
left: 50%;
transform: translateY(100%) translateY(2px) translateX(-50%);
z-index: 10;
}
[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
display:block;
}
</style> </style>
</head> </head>