chore: release v2.2.0 (#602)

* feat(slider): add option to hide slider value (#494)

* feat(slider): hideValue prop added

* test(slider): test added for hideValue prop

docs(slider): add hideValue prop

docs(slider): add hideValue prop for cn docs

feat(slider): ensure the dot stays round when no content

test(slider): update snapshots

* feat(loading): apply width & height props (#500)

* feat(loading): apply width & height props

* test(loading): test case added & updating snapshots

* fix(loading): add a string type for size prop

test(loading): update test case & snapshots

* feat(loading): support custom the ratio of spaces

* docs(loading): append size and spaceRatio

test(loading): update snapshots

Co-authored-by: unix <unix.bio@gmail.com>

* chore(deps): update styled-jsx to ^3.3.1 (#520)

* chore(deps): update styled-jsx to ^3.3.1

update styled-jsx to ^3.3.1 to allow compatiblity with react@^17

* fix(modules): fix 695-issue to compatible with React 17

* docs: fix module error caused by styled-jsx update

Co-authored-by: unix <unix.bio@gmail.com>

* chore: release v2.2.0-rc.0

* fix(modal): disable backdrop even if actions missing (#532)

* fix: upgrade to be compatible with React-17's event system (#533)

* feat: useKeyboard hooks (#541)

* feat(keyboard): create keyboard hooks

* feat(usekeyboard): redesign event handler to match keyboard events from browser

\

* test(usekeyboard): add testcase

* docs(usekeyboard): create new hooks document

* chore: release v2.2.0-rc.1

* feat(auto-complete): add forwardRef for input element (#542)

* feat(auto-complete): add forwardRef for input element

* test(auto-complete): add testcase to ensure ref is available

* docs(auto-complete): append props for ref

* chore: release v2.2.0-rc.2

* fix(auto-complete): fix size of loading icon (#546)

* chore: release v2.2.0-rc.3

* fix(auto-complete): hide shadow when no content (#547)

* chore: release v2.2.0-rc.4

* feat: add status prop in checkbox, radio, select, slider and toggle (#530)

* feat: added status prop to set color by states

test: check status success, warning and error

* docs: added playground example and API reference

fix: replaced ´_´ as it's not recommended to use

fix: removed redundant return

refactor: renamed prop from status to type

test: update test with the renamed prop

* docs: update prop references from status to type

fix: status prop not updated to type

fix: missing return

* fix(select): set icons and hover state to follow the theme

* test(slider): update snapshots

* chore: always use relative paths when import types

Co-authored-by: unix <unix.bio@gmail.com>

* feat(auto-complete): add props for popup container (#558)

* feat(auto-complete): add props for popup container

* docs(auto-complete): add attribute for popup container

* chore: release v2.2.0-rc.5

* fix: fix path error under esm

* chore: release v2.2.0-rc.6

* feat(scaleable): add scaleable props to each component (#531)

* feat(scaleable): add scaleable props to each component

* chore(scaleable): update the exported type

* feat: apply scaleable to components

chore: remove with-default

test: improve testcase for scaleable

chore: resolve test warning

ci: upgrade nodejs to latest lts

docs: fix type error in document site

* docs: update documents to be compatible with scaleable

chore: fix build errors

* chore: remove all size-related attributes

docs: improve guide document

* docs: add scaleable documentation

test: update snapshots

chore: remove unused

* feat: add scaleable to grid components

* docs: improve docs

* test: update snapshots

* fix(grid): fix basic component props

* feat: export all types related to components (#562)

* feat: export all types related to components

fix(tooltip): fix the vertical offset of the arrow

* refactor: optimize events of all popup related components

* test: append testcases for popup base component

* test: add testcase for visible events

* test: update snapshots

* fix(bundle): fix modules missing in yarn berry (#563)

* chore: add peer dependencies

* fix(bundle): fix modules missing in yarn berry

* chore: upgrade configs for jest 27

* chore(examples): upgrade next examples for scaleable (#564)

* chore: release v2.2.0-rc.7

* feat(rating): a new component rating indicator (#543)

* chore(deps): bump lodash from 4.17.20 to 4.17.21 (#537)

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.20...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* (feature) rating state working and islocked working

* (feature) custom emojis for the ratings added

* refactor(rating): migrate component to scaleable

* feat(rating): use inline icon component

test(rating): update testcase

* docs(rating): add document for zh-cn

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: unix <unix.bio@gmail.com>

* refactor(table): redesign interfaces to improve the experience in TypeScript (#569)

* refactor(table): redesign interfaces to improve the experience in TypeScript

* docs: upgrade to new type exports

* style: fix lint warnings

* docs: fix sidebar text-transform (#570)

* docs: improve the copywriting content of the document (#571)

* docs: export individual style types for each component

* docs: improve the copywriting content of the document

* docs: optimize the document site experience on mobile devices

* chore: release v2.2.0-rc.8

* feat(modal): responds to keyboard events when modal is displayed (#574)

* docs: redesign mobile navigation (#576)

* docs: redesign mobile navigation

* docs: fix subheading active color

* fix(avatar): fix margin on first child (#578)

Co-authored-by: witt <unix.bio@gmail.com>

* feat(select): imporve the focus events to export simulated ref (#579)

* feat(select): imporve the focus events to export simulated ref

* test: improve testcase and fix warnings

* docs(select): add label and divider to props docs

* fix: rename hymlType to htmlType (#599)

* feat(drawer): create component (#575)

* feat(drawer): create component

* feat(drawer): refinement of drawer component

* test: update tool chain for jest

* test: simplify events case for jest

* docs(drawer): add playground

* docs(drawer): add api docs

* docs: add home page (#573)

* docs: add home page

* docs(homepage): apply suggestions from code review

* docs(homepage): make cards clickable

Co-authored-by: witt <unix.bio@gmail.com>

* test: update snapshots for scaleable

* chore: update lock file

* chore: upgrade styled-jsx

* test: update snapshots for styled-jsx

Co-authored-by: Deepankar <deep14bhade@gmail.com>
Co-authored-by: Deepankar <statisticsaffinity@gmail.com>
Co-authored-by: Florian Levis <levis.florian@gmail.com>
Co-authored-by: gepd <guillermoepd@hotmail.com>
Co-authored-by: Nils J <nils.jorek@gmx.de>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ofek Ashery <ofek.ashery@gmail.com>
Co-authored-by: Sanna Jammeh <50969683+sannajammeh@users.noreply.github.com>
This commit is contained in:
witt
2021-08-13 17:31:45 +08:00
committed by GitHub
parent 89e82c88ed
commit 299f7741ea
504 changed files with 30398 additions and 21110 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,6 @@ import React from 'react'
import { mount } from 'enzyme'
import { Image } from 'components'
import { updateWrapper } from 'tests/utils'
import { act } from 'react-dom/test-utils'
const url =
'data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA' +
@@ -67,28 +66,4 @@ describe('Image', () => {
expect((img.getDOMNode() as HTMLImageElement).complete).toEqual(true)
expect(wrapper.find('.skeleton').length).toBe(0)
})
it('should zooming image when width so small', async () => {
window.getComputedStyle = jest.fn().mockImplementation(() => ({
width: '10px',
}))
const wrapper = mount(
<div style={{ width: '10px' }}>
<Image src={url} width={100} height={100} />
</div>,
)
expect(wrapper.find('.image').html()).toContain('height: auto;')
;(window.getComputedStyle as jest.Mock).mockRestore()
window.getComputedStyle = jest.fn().mockImplementation(() => ({
width: '110px',
}))
act(() => {
window.dispatchEvent(new Event('resize'))
})
await updateWrapper(wrapper)
expect(wrapper.find('.image').html()).not.toContain('height: auto;')
;(window.getComputedStyle as jest.Mock).mockRestore()
})
})

View File

@@ -2,13 +2,19 @@ import React from 'react'
const ImageBrowserHttpsIcon = () => {
return (
<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M5 10.2H19V21H5V10.2Z" />
<path
fillRule="evenodd"
clipRule="evenodd"
d="M12 12C13.933 12 15.5 10.3882 15.5 8.4C15.5 6.41177 13.933 4.8 12 4.8C10.067 4.8 8.5 6.41177 8.5 8.4C8.5 10.3882 10.067 12 12 12ZM12 13.8C14.8995 13.8 17.25 11.3823 17.25 8.4C17.25 5.41766 14.8995 3 12 3C9.10051 3 6.75 5.41766 6.75 8.4C6.75 11.3823 9.10051 13.8 12 13.8Z"
/>
<style jsx>{`
svg {
width: 1em;
height: 1em;
}
`}</style>
</svg>
)
}

View File

@@ -2,30 +2,30 @@ import React, { useMemo } from 'react'
import Link from '../link'
import { Props as LinkProps } from '../link/link'
import useTheme from '../use-theme'
import withDefaults from '../utils/with-defaults'
import ImageBrowserHttpsIcon from './image-browser-https-icon'
import { getBrowserColors, BrowserColors } from './styles'
import useScaleable, { withScaleable } from '../use-scaleable'
type AnchorProps = Omit<React.AnchorHTMLAttributes<any>, keyof LinkProps>
export type ImageAnchorProps = Omit<React.AnchorHTMLAttributes<any>, keyof LinkProps>
interface Props {
title?: string
url?: string
showFullLink?: boolean
invert?: boolean
anchorProps?: AnchorProps
anchorProps?: ImageAnchorProps
className?: string
}
const defaultProps = {
className: '',
showFullLink: false,
anchorProps: {} as AnchorProps,
anchorProps: {} as ImageAnchorProps,
invert: false,
}
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type ImageBrowserProps = Props & typeof defaultProps & NativeAttrs
export type ImageBrowserProps = Props & NativeAttrs
const getHostFromUrl = (url: string) => {
try {
@@ -41,7 +41,7 @@ const getTitle = (title: string, colors: BrowserColors) => (
<style jsx>{`
.title {
color: ${colors.titleColor};
font-size: 0.75rem;
font-size: 0.75em;
}
`}</style>
</div>
@@ -51,7 +51,7 @@ const getAddressInput = (
url: string,
showFullLink: boolean,
colors: BrowserColors,
anchorProps: AnchorProps,
anchorProps: ImageAnchorProps,
) => (
<div className="address-input">
<span className="https">
@@ -62,7 +62,7 @@ const getAddressInput = (
</Link>
<style jsx>{`
.address-input {
height: 1.75rem;
height: 1.75em;
max-width: 60%;
min-width: 40%;
background-color: ${colors.inputBgColor};
@@ -77,7 +77,7 @@ const getAddressInput = (
}
.address-input :global(*) {
font-size: 0.75rem;
font-size: 0.75em;
color: inherit;
}
@@ -91,30 +91,43 @@ const getAddressInput = (
}
.https {
width: 12px;
height: 12px;
margin-right: 5px;
width: 0.75em;
height: 0.75em;
font-size: 1em;
margin-right: 0.31em;
user-select: none;
margin-top: -1px;
color: inherit;
display: inline-flex;
align-items: center;
}
`}</style>
</div>
)
const ImageBrowser = React.forwardRef<
const ImageBrowserComponent = React.forwardRef<
HTMLDivElement,
React.PropsWithChildren<ImageBrowserProps>
>(
(
{ url, title, children, showFullLink, invert, anchorProps, className, ...props },
{
url,
title,
children,
showFullLink,
invert,
anchorProps,
className,
...props
}: React.PropsWithChildren<ImageBrowserProps> & typeof defaultProps,
ref: React.Ref<HTMLDivElement>,
) => {
const theme = useTheme()
const colors = useMemo(() => getBrowserColors(invert, theme.palette), [
invert,
theme.palette,
])
const { SCALES } = useScaleable()
const colors = useMemo(
() => getBrowserColors(invert, theme.palette),
[invert, theme.palette],
)
const input = useMemo(() => {
if (url) return getAddressInput(url, showFullLink, colors, anchorProps)
if (title) return getTitle(title, colors)
@@ -136,11 +149,15 @@ const ImageBrowser = React.forwardRef<
.bowser {
background-color: transparent;
box-shadow: ${theme.expressiveness.shadowLarge};
width: max-content;
max-width: 100%;
margin: 0 auto;
border-radius: ${theme.layout.radius};
overflow: hidden;
font-size: ${SCALES.font(1)};
width: ${SCALES.width(1, 'max-content')};
height: ${SCALES.height(1, 'auto')};
margin: ${SCALES.mt(0)} ${SCALES.mr(0, 'auto')} ${SCALES.mb(0)}
${SCALES.ml(0, 'auto')};
padding: ${SCALES.pt(0)} ${SCALES.pr(0)} ${SCALES.pb(0)} ${SCALES.pl(0)};
}
.bowser :global(.image) {
@@ -149,7 +166,7 @@ const ImageBrowser = React.forwardRef<
}
header {
height: 2.5rem;
height: 2.5em;
width: 100%;
display: flex;
align-items: center;
@@ -171,14 +188,17 @@ const ImageBrowser = React.forwardRef<
display: flex;
align-items: center;
user-select: none;
font-size: inherit;
}
.traffic span {
border-radius: 50%;
width: 0.75rem;
height: 0.75rem;
width: 0.75em;
height: 0.75em;
max-width: 20px;
max-height: 20px;
display: inline-block;
margin-right: 0.5rem;
margin-right: 0.5em;
}
.close {
@@ -198,4 +218,7 @@ const ImageBrowser = React.forwardRef<
},
)
export default withDefaults(ImageBrowser, defaultProps)
ImageBrowserComponent.defaultProps = defaultProps
ImageBrowserComponent.displayName = 'GeistImageBrowser'
const ImageBrowser = withScaleable(ImageBrowserComponent)
export default ImageBrowser

View File

@@ -1,19 +1,18 @@
import React from 'react'
import withDefaults from '../utils/with-defaults'
import useTheme from '../use-theme'
interface Props {
opacity: number
opacity?: number
}
const defaultProps = {
opacity: 0.5,
}
export type ImageSkeletonProps = Props & typeof defaultProps
export type ImageSkeletonProps = Props
const ImageSkeleton: React.FC<ImageSkeletonProps> = React.memo(
({ opacity, ...props }) => {
({ opacity, ...props }: ImageSkeletonProps & typeof defaultProps) => {
const theme = useTheme()
return (
<div className="skeleton" {...props}>
@@ -53,4 +52,6 @@ const ImageSkeleton: React.FC<ImageSkeletonProps> = React.memo(
},
)
export default withDefaults(ImageSkeleton, defaultProps)
ImageSkeleton.defaultProps = defaultProps
ImageSkeleton.displayName = 'GeistImageSkeleton'
export default ImageSkeleton

View File

@@ -1,54 +1,40 @@
import React, { useEffect, useRef, useState } from 'react'
import useTheme from '../use-theme'
import ImageSkeleton from './image.skeleton'
import ImageBrowser from './image-browser'
import useRealShape from '../utils/use-real-shape'
import useCurrentState from '../utils/use-current-state'
import useResize from '../utils/use-resize'
import useScaleable, { withScaleable } from '../use-scaleable'
interface Props {
src: string
disableAutoResize?: boolean
disableSkeleton?: boolean
width?: number
height?: number
className?: string
scale?: string
maxDelay?: number
}
const defaultProps = {
disableSkeleton: false,
disableAutoResize: false,
className: '',
scale: '100%',
maxDelay: 3000,
}
type NativeAttrs = Omit<React.ImgHTMLAttributes<any>, keyof Props>
export type ImageProps = Props & typeof defaultProps & NativeAttrs
export type ImageProps = Props & NativeAttrs
const Image: React.FC<ImageProps> = ({
const ImageComponent: React.FC<ImageProps> = ({
src,
width,
height,
disableSkeleton,
className,
scale,
maxDelay,
disableAutoResize,
...props
}) => {
}: ImageProps & typeof defaultProps) => {
const { SCALES, getScaleableProps } = useScaleable()
const width = getScaleableProps(['width', 'w'])
const height = getScaleableProps(['height', 'h'])
const showAnimation = !disableSkeleton && width && height
const w = width ? `${width}px` : 'auto'
const h = height ? `${height}px` : 'auto'
const theme = useTheme()
const [loading, setLoading] = useState<boolean>(true)
const [showSkeleton, setShowSkeleton] = useState<boolean>(true)
const [zoomHeight, setZoomHeight, zoomHeightRef] = useCurrentState<string>(h)
const imageRef = useRef<HTMLImageElement>(null)
const [shape, updateShape] = useRealShape(imageRef)
const imageLoaded = () => {
if (!showAnimation) return
@@ -74,55 +60,26 @@ const Image: React.FC<ImageProps> = ({
return () => clearTimeout(timer)
}, [loading])
/**
* On mobile devices, the render witdth may be less than CSS width value.
* If the image is scaled, set the height manually.
* This is to ensure the aspect ratio of the image.
*
* If the image is auto width, ignore all.
*/
useEffect(() => {
if (disableAutoResize) return
const notLoaded = shape.width === 0
const isAutoZoom = zoomHeightRef.current === 'auto'
if (notLoaded || !width || !height) return
if (shape.width < width) {
!isAutoZoom && setZoomHeight('auto')
} else {
isAutoZoom && setZoomHeight(h)
}
}, [shape, width])
useResize(() => {
if (disableAutoResize) return
updateShape()
})
return (
<div className={`image ${className}`}>
{showSkeleton && showAnimation && <ImageSkeleton opacity={loading ? 0.5 : 0} />}
<img
ref={imageRef}
width={width}
height={height}
onLoad={imageLoaded}
src={src}
{...props}
/>
<img ref={imageRef} onLoad={imageLoaded} src={src} {...props} />
<style jsx>{`
.image {
width: ${w};
height: ${zoomHeight};
margin: 0 auto;
position: relative;
border-radius: ${theme.layout.radius};
overflow: hidden;
max-width: 100%;
width: ${SCALES.width(1, 'auto')};
height: ${SCALES.height(1, 'auto')};
margin: ${SCALES.mt(0)} ${SCALES.mr(0, 'auto')} ${SCALES.mb(0)}
${SCALES.ml(0, 'auto')};
padding: ${SCALES.pt(0)} ${SCALES.pr(0)} ${SCALES.pb(0)} ${SCALES.pl(0)};
}
img {
width: ${scale};
height: ${scale};
width: ${SCALES.width(1, 'auto')};
height: ${SCALES.height(1, 'auto')};
object-fit: scale-down;
display: block;
}
@@ -131,13 +88,7 @@ const Image: React.FC<ImageProps> = ({
)
}
type MemoImageComponent<P = {}> = React.NamedExoticComponent<P> & {
Browser: typeof ImageBrowser
}
type ComponentProps = Partial<typeof defaultProps> &
Omit<Props, keyof typeof defaultProps> &
NativeAttrs
Image.defaultProps = defaultProps
export default React.memo(Image) as MemoImageComponent<ComponentProps>
ImageComponent.defaultProps = defaultProps
ImageComponent.displayName = 'GeistImage'
const Image = withScaleable(ImageComponent)
export default Image

View File

@@ -1,6 +1,11 @@
import Image from './image'
import ImageBrowser from './image-browser'
Image.Browser = ImageBrowser
export type ImageComponentType = typeof Image & {
Browser: typeof ImageBrowser
}
;(Image as ImageComponentType).Browser = ImageBrowser
export default Image
export type { ImageProps } from './image'
export type { ImageBrowserProps, ImageAnchorProps } from './image-browser'
export default Image as ImageComponentType

View File

@@ -1,4 +1,4 @@
import { GeistUIThemesPalette } from 'components/themes/presets'
import { GeistUIThemesPalette } from '../themes/presets'
export type BrowserColors = {
color: string