-
Notifications
You must be signed in to change notification settings - Fork 317
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 #7082 from TheThingsNetwork/feature/console-search
Console search
- Loading branch information
Showing
44 changed files
with
1,608 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright © 2024 The Things Network Foundation, The Things Industries B.V. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import React, { useCallback, useEffect, useRef } from 'react' | ||
|
||
import PropTypes from '@ttn-lw/lib/prop-types' | ||
import combineRefs from '@ttn-lw/lib/combine-refs' | ||
|
||
import style from './scroll-fader.styl' | ||
|
||
// ScrollFader is a component that fades out the content of a container when it | ||
// is scrolled. It is used for scrollable elements that need some visual | ||
// indication that they are scrollable, but do not have a scrollbar. | ||
// The indication only shows when the content is scrolled. | ||
|
||
const ScrollFader = React.forwardRef(({ children, className, fadeHeight }, ref) => { | ||
const internalRef = useRef() | ||
const combinedRef = combineRefs([ref, internalRef]) | ||
|
||
const handleScroll = useCallback(() => { | ||
const container = internalRef.current | ||
const { scrollTop, scrollHeight, clientHeight } = container | ||
const scrollable = scrollHeight - clientHeight | ||
const scrollGradientTop = container.querySelector(`.${style.scrollGradientTop}`) | ||
const scrollGradientBottom = container.querySelector(`.${style.scrollGradientBottom}`) | ||
|
||
if (scrollGradientTop) { | ||
const opacity = scrollTop < fadeHeight ? scrollTop / fadeHeight : 1 | ||
scrollGradientTop.style.opacity = opacity | ||
} | ||
|
||
if (scrollGradientBottom) { | ||
const scrollEnd = scrollable - fadeHeight | ||
const opacity = scrollTop < scrollEnd ? 1 : (scrollable - scrollTop) / fadeHeight | ||
scrollGradientBottom.style.opacity = opacity | ||
} | ||
}, [fadeHeight]) | ||
|
||
useEffect(() => { | ||
const container = internalRef.current | ||
if (!container) return | ||
|
||
const mutationObserver = new MutationObserver(() => { | ||
handleScroll() | ||
}) | ||
|
||
// Run the calculation whenever the children change. | ||
mutationObserver.observe(container, { attributes: false, childList: true, subtree: false }) | ||
|
||
handleScroll() // Call once on mount if needed | ||
container.addEventListener('scroll', handleScroll) | ||
window.addEventListener('resize', handleScroll) | ||
|
||
return () => { | ||
// Cleanup observer and event listeners | ||
mutationObserver.disconnect() | ||
container.removeEventListener('scroll', handleScroll) | ||
window.removeEventListener('resize', handleScroll) | ||
} | ||
}, [handleScroll]) | ||
|
||
return ( | ||
<div | ||
ref={combinedRef} | ||
onScroll={handleScroll} | ||
className={className} | ||
style={{ | ||
position: 'relative', | ||
}} | ||
> | ||
<div className={style.scrollGradientTop} /> | ||
{children} | ||
<div className={style.scrollGradientBottom} /> | ||
</div> | ||
) | ||
}) | ||
|
||
ScrollFader.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
className: PropTypes.string, | ||
fadeHeight: PropTypes.number, | ||
} | ||
|
||
ScrollFader.defaultProps = { | ||
className: undefined, | ||
fadeHeight: 40, | ||
} | ||
|
||
export default ScrollFader |
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,37 @@ | ||
// Copyright © 2024 The Things Network Foundation, The Things Industries B.V. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
$scroll-gradient-height = 1rem | ||
|
||
// Add a gradient to the bottom of the sidebar | ||
// to signify that there is more content below. | ||
.scroll-gradient-top, .scroll-gradient-bottom | ||
position: sticky | ||
left: 0 | ||
right: 0 | ||
height: $scroll-gradient-height | ||
z-index: $zi.slight | ||
opacity: 0 | ||
pointer-events: none | ||
|
||
.scroll-gradient-top | ||
top: 0 | ||
margin-bottom: - $scroll-gradient-height | ||
background: linear-gradient(0deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .05)) | ||
|
||
.scroll-gradient-bottom | ||
bottom: 0 | ||
margin-top: - $scroll-gradient-height | ||
background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .05)) | ||
|
Oops, something went wrong.