-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added scroll handling for webcompat dialog
Signed-off-by: Vadym Struts <[email protected]>
- Loading branch information
1 parent
130d286
commit 6c13221
Showing
7 changed files
with
207 additions
and
16 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
72 changes: 72 additions & 0 deletions
72
components/webcompat_reporter/ui/components/ShortenedUrl.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,72 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import * as React from 'react' | ||
|
||
import { NonInteractiveURL } from './basic' | ||
|
||
interface ShortenedUrlProps { | ||
url: string | ||
maxLength: number | ||
interactive: boolean | ||
} | ||
|
||
interface ShortenedUrlState { | ||
shortenedUrl: string | ||
} | ||
|
||
class ShortenedUrl | ||
extends React.PureComponent<ShortenedUrlProps, ShortenedUrlState> { | ||
static defaultProps: Partial<ShortenedUrlProps> = { | ||
maxLength: 100, | ||
interactive: false | ||
} | ||
|
||
constructor(props: ShortenedUrlProps) { | ||
super(props) | ||
this.state = { | ||
shortenedUrl: this.shortenUrl(props.url, props.maxLength), | ||
} | ||
} | ||
|
||
handleOnInteractiveClick = | ||
async (ev: React.MouseEvent<HTMLParagraphElement>) => { | ||
if (this.props.interactive) { | ||
window.open(this.props.url, '_blank', 'noopener') | ||
} | ||
} | ||
|
||
shortenUrl(url: string, maxLength: number): string { | ||
if (url.length <= maxLength) { | ||
return url | ||
} | ||
const dots = '......' | ||
const partLength = Math.floor((maxLength - dots.length) / 2) | ||
const start = url.slice(0, partLength) | ||
const end = url.slice(-partLength) | ||
|
||
return `${start}${dots}${end}` | ||
} | ||
|
||
componentDidUpdate(prevProps: ShortenedUrlProps) { | ||
if (prevProps.url !== this.props.url || | ||
prevProps.maxLength !== this.props.maxLength) { | ||
this.setState({ | ||
shortenedUrl: this.shortenUrl( | ||
this.props.url, this.props.maxLength), | ||
}) | ||
} | ||
} | ||
|
||
render() { | ||
const { shortenedUrl } = this.state | ||
return ( | ||
<NonInteractiveURL onClick={this.handleOnInteractiveClick}> | ||
{shortenedUrl} | ||
</NonInteractiveURL>) | ||
} | ||
} | ||
|
||
export default ShortenedUrl; |
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 |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
<style> | ||
#root { | ||
height: 100%; | ||
overflow-x: hidden; | ||
overflow-y: auto; | ||
} | ||
body { | ||
margin: 0; | ||
|
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