index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/geist-org/geist-ui/components/toggle
petrpan-code/geist-org/geist-ui/components/toggle/__tests__/index.test.tsx
import React from 'react' import { mount, ReactWrapper } from 'enzyme' import { Toggle } from 'components' import { nativeEvent, updateWrapper } from 'tests/utils' const expectToggleIsChecked = (wrapper: ReactWrapper) => { expect(wrapper.find('.checked').length).not.toBe(0) } const expectToggleIsUnChecked = (wrappe...
2,800
0
petrpan-code/geist-org/geist-ui/components/toggle/__tests__
petrpan-code/geist-org/geist-ui/components/toggle/__tests__/__snapshots__/index.test.tsx.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Toggle should render correctly 1`] = ` "<label class=\\"\\"><input type=\\"checkbox\\"><div class=\\"toggle\\"><span class=\\"inner\\"></span></div><style> label { -webkit-tap-highlight-color: transparent; display: inline-block; ...
2,801
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tooltip/helper.ts
import { MutableRefObject } from 'react' export interface ReactiveDomReact { top: number bottom: number left: number right: number width: number height: number } const defaultRect: ReactiveDomReact = { top: -1000, left: -1000, right: -1000, bottom: -1000, width: 0, height: 0, } export const g...
2,802
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tooltip/index.ts
import Tooltip from './tooltip' export type { TooltipProps, TooltipOnVisibleChange, TooltipTypes, TooltipTriggers, TooltipPlacement, } from './tooltip' export default Tooltip
2,803
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tooltip/placement.ts
import { Placement } from '../utils/prop-types' interface ParentDomRect { top: number left: number right: number bottom: number width: number height: number } export interface TooltipPosition { top: string left: string transform: string } export const defaultTooltipPosition = { top: '-1000px', ...
2,804
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tooltip/styles.ts
import { SnippetTypes } from '../utils/prop-types' import { GeistUIThemesPalette } from '../themes/presets' export type TooltipColors = { bgColor: string color: string } export const getColors = ( type: SnippetTypes, palette: GeistUIThemesPalette, ): TooltipColors => { const colors: { [key in SnippetTypes]:...
2,805
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tooltip/tooltip-content.tsx
import React, { MutableRefObject, useEffect, useMemo, useRef, useState } from 'react' import { createPortal } from 'react-dom' import useTheme from '../use-theme' import usePortal from '../utils/use-portal' import useResize from '../utils/use-resize' import CssTransition from '../shared/css-transition' import useClickA...
2,806
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tooltip/tooltip-icon.tsx
import React, { useMemo } from 'react' import { getIconPosition } from './placement' import { Placement } from '../utils/prop-types' import useTheme from '../use-theme' interface Props { placement: Placement shadow: boolean } const TooltipIcon: React.FC<Props> = ({ placement, shadow }) => { const theme = useThe...
2,807
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tooltip/tooltip.tsx
import React, { useEffect, useMemo, useRef, useState } from 'react' import TooltipContent, { TooltipIconOffset } from './tooltip-content' import useClickAway from '../utils/use-click-away' import { TriggerTypes, Placement, SnippetTypes } from '../utils/prop-types' import { withScale } from '../use-scale' import { getRe...
2,808
0
petrpan-code/geist-org/geist-ui/components/tooltip
petrpan-code/geist-org/geist-ui/components/tooltip/__test__/index.test.tsx
import React from 'react' import { mount, ReactWrapper } from 'enzyme' import { Button, Tooltip, GeistProvider } from 'components' import { nativeEvent, updateWrapper } from 'tests/utils' import { act } from 'react-dom/test-utils' const expectTooltipIsShow = (wrapper: ReactWrapper) => { expect(wrapper.find('.inner')...
2,809
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/index.ts
import Tree from './tree' import TreeFile from './tree-file' import TreeFolder from './tree-folder' export type TreeComponentType = typeof Tree & { File: typeof TreeFile Folder: typeof TreeFolder } ;(Tree as TreeComponentType).File = TreeFile ;(Tree as TreeComponentType).Folder = TreeFolder export type { TreeProp...
2,810
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree-context.ts
import React from 'react' export interface TreeConfig { onFileClick?: (path: string) => void initialExpand: boolean isImperative: boolean } const defaultContext = { initialExpand: false, isImperative: false, } export const TreeContext = React.createContext<TreeConfig>(defaultContext) export const useTreeC...
2,811
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree-file-icon.tsx
import React from 'react' import useTheme from '../use-theme' export interface TreeFileIconProps { color?: string width?: number height?: number } const defaultProps = { width: 22, height: 22, } const TreeFileIcon: React.FC<TreeFileIconProps> = ({ color, width, height, }: TreeFileIconProps & typeof d...
2,812
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree-file.tsx
import React, { useMemo } from 'react' import useTheme from '../use-theme' import TreeFileIcon from './tree-file-icon' import { useTreeContext } from './tree-context' import TreeIndents from './tree-indents' import { makeChildPath, stopPropagation } from './tree-help' import useClasses from '../use-classes' interface ...
2,813
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree-folder-icon.tsx
import React from 'react' import useTheme from '../use-theme' export interface TreeFolderIconProps { color?: string width?: number height?: number } const defaultProps = { width: 22, height: 22, } const TreeFolderIcon: React.FC<TreeFolderIconProps> = ({ color, width, height, }: TreeFolderIconProps & ...
2,814
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree-folder.tsx
import React, { useEffect, useMemo, useState } from 'react' import useTheme from '../use-theme' import { setChildrenProps } from '../utils/collections' import TreeFile from './tree-file' import Expand from '../shared/expand' import TreeIndents from './tree-indents' import { useTreeContext } from './tree-context' import...
2,815
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree-help.ts
import React, { ReactNode } from 'react' export const sortChildren = ( children: ReactNode | undefined, folderComponentType: React.ElementType, ) => { return React.Children.toArray(children).sort((a, b) => { if (!React.isValidElement(a) || !React.isValidElement(b)) return 0 if (a.type !== b.type) return ...
2,816
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree-indents.tsx
import React from 'react' interface Props { count: number } const TreeIndents: React.FC<Props> = ({ count }) => { if (count === 0) return null return ( /* eslint-disable react/jsx-no-useless-fragment */ <> {[...new Array(count)].map((_, index) => ( <span className="indent" key={`indent-${i...
2,817
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree-status-icon.tsx
import React from 'react' import useTheme from '../use-theme' export interface TreeStatusIconProps { color?: string width?: number height?: number active?: boolean } const defaultProps = { width: 12, height: 12, active: false, } const TreeStatusIcon: React.FC<TreeStatusIconProps> = ({ color, width,...
2,818
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/tree/tree.tsx
import React, { useMemo } from 'react' import TreeFile from './tree-file' import TreeFolder from './tree-folder' import { TreeContext } from './tree-context' import { tuple } from '../utils/prop-types' import { sortChildren } from './tree-help' import useClasses from '../use-classes' const FileTreeValueType = tuple('d...
2,819
0
petrpan-code/geist-org/geist-ui/components/tree
petrpan-code/geist-org/geist-ui/components/tree/__tests__/index.test.tsx
import React from 'react' import { mount } from 'enzyme' import { Tree } from 'components' import { nativeEvent } from 'tests/utils' import { TreeFile } from '../tree' const mockFiles: Array<TreeFile> = [ { type: 'file', name: 'cs.js', }, { type: 'directory', name: 'bin', files: [ { ...
2,820
0
petrpan-code/geist-org/geist-ui/components/tree/__tests__
petrpan-code/geist-org/geist-ui/components/tree/__tests__/__snapshots__/index.test.tsx.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Tree should mount correctly 1`] = ` <GeistTreeFile className="" level={0} name="package.json" parentPath="" /> `; exports[`Tree should mount correctly 2`] = ` <GeistTreeFolder className="" level={0} name="components" parentPath="" /> `; exports[`Tre...
2,821
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-all-themes/all-themes-context.ts
import React from 'react' import Themes from '../themes/themes' import { GeistUIThemes } from '../themes/presets' export type AllThemesConfig = { themes: Array<GeistUIThemes> } const defaultAllThemesConfig = { themes: Themes.getPresets(), } export const AllThemesContext: React.Context<AllThemesConfig> = React.cr...
2,822
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-all-themes/index.ts
import { useAllThemes } from './all-themes-context' export type { AllThemesConfig } from './all-themes-context' export default useAllThemes
2,823
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-body-scroll/index.ts
import useBodyScroll from './use-body-scroll' export type { BodyScrollOptions } from './use-body-scroll' export default useBodyScroll
2,824
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-body-scroll/use-body-scroll.ts
import { Dispatch, RefObject, SetStateAction, useEffect, useRef, useState } from 'react' export type ElementStackItem = { overflow: string paddingRight: string } export type BodyScrollOptions = { scrollLayer?: boolean delayReset?: number } const defaultOptions: BodyScrollOptions = { scrollLayer: false, d...
2,825
0
petrpan-code/geist-org/geist-ui/components/use-body-scroll
petrpan-code/geist-org/geist-ui/components/use-body-scroll/__tests__/body-scroll.test.tsx
import React, { RefObject } from 'react' import { useBodyScroll } from 'components' import { act, renderHook } from '@testing-library/react-hooks' import { sleep } from 'tests/utils' describe('UseBodyScroll', () => { it('should work correctly', () => { const ref = React.createRef<HTMLDivElement>() ;(ref as a...
2,826
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-classes/index.ts
import { default as useClasses } from './use-classes' export default useClasses
2,827
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-classes/use-classes.ts
export type classNamesObject = Record< string, boolean | string | number | null | undefined > export type className = string | classNamesObject | null | undefined | boolean | number const classObjectToString = (className: classNamesObject) => { const keys = Object.keys(className) const len = keys.length let ...
2,828
0
petrpan-code/geist-org/geist-ui/components/use-classes
petrpan-code/geist-org/geist-ui/components/use-classes/__tests__/index.test.tsx
import { useClasses } from 'components' import { expect } from '@jest/globals' describe('useClasses', () => { it('should be return string always', () => { const str = Math.random().toString() expect(typeof useClasses(str)).toEqual('string') expect(typeof useClasses(true)).toEqual('string') expect(typ...
2,829
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-click-away/index.ts
import useClickAway from './use-click-away' export default useClickAway
2,830
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-click-away/use-click-away.ts
import { MutableRefObject, useEffect, useRef } from 'react' export type ClickAwayGetContainer = () => HTMLElement | null const useClickAway = ( ref: MutableRefObject<HTMLElement | null>, handler: (event: Event) => void, ) => { const handlerRef = useRef(handler) useEffect(() => { handlerRef.current = handl...
2,831
0
petrpan-code/geist-org/geist-ui/components/use-click-away
petrpan-code/geist-org/geist-ui/components/use-click-away/__tests__/click-away.test.tsx
import React from 'react' import { renderHook } from '@testing-library/react-hooks' import { useClickAway } from 'components' const simulateNativeClick = (el: Element) => { el.dispatchEvent( new MouseEvent('click', { view: window, bubbles: true, cancelable: true, }), ) } describe('UseCli...
2,832
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-clipboard/index.ts
import useClipboard from './use-clipboard' export type { UseClipboardOptions, UseClipboardResult } from './use-clipboard' export default useClipboard
2,833
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-clipboard/use-clipboard.ts
import usePortal from '../utils/use-portal' import useWarning from '../utils/use-warning' import { useCallback } from 'react' export type UseClipboardOptions = { onError: () => unknown } export type UseClipboardResult = { copy: (text: string) => void } const defaultOptions: UseClipboardOptions = { onError: () ...
2,834
0
petrpan-code/geist-org/geist-ui/components/use-clipboard
petrpan-code/geist-org/geist-ui/components/use-clipboard/__tests__/clipboard.test.tsx
import { useClipboard } from 'components' import { renderHook } from '@testing-library/react-hooks' describe('UseClipboard', () => { beforeAll(() => { window.getSelection = jest.fn().mockImplementation(() => ({ removeAllRanges: jest.fn(), addRange: jest.fn(), })) document.createRange = jest.f...
2,835
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-current-state/index.ts
import useCurrentState from './use-current-state' export default useCurrentState
2,836
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-current-state/use-current-state.ts
import { Dispatch, MutableRefObject, SetStateAction, useEffect, useRef, useState, } from 'react' export type CurrentStateType<S> = [S, Dispatch<SetStateAction<S>>, MutableRefObject<S>] const useCurrentState = <S>(initialState: S | (() => S)): CurrentStateType<S> => { const [state, setState] = useState<S...
2,837
0
petrpan-code/geist-org/geist-ui/components/use-current-state
petrpan-code/geist-org/geist-ui/components/use-current-state/__tests__/current-state.test.tsx
import React, { useEffect } from 'react' import { mount } from 'enzyme' import { useCurrentState } from 'components' import { renderHook, act } from '@testing-library/react-hooks' describe('UseCurrentState', () => { it('should work correctly', () => { const { result } = renderHook(() => useCurrentState('')) ...
2,838
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-input/index.ts
import useInput from './use-input' export type { BindingsChangeTarget } from './use-input' export default useInput
2,839
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-input/use-input.tsx
import React, { Dispatch, MutableRefObject, SetStateAction } from 'react' import useCurrentState from '../utils/use-current-state' export type BindingsChangeTarget = | React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | string const useInput = ( initialValue: string, ): { state: string setState: Dis...
2,840
0
petrpan-code/geist-org/geist-ui/components/use-input
petrpan-code/geist-org/geist-ui/components/use-input/__tests__/use-input.test.tsx
import React, { useEffect } from 'react' import { mount } from 'enzyme' import { Input, useInput } from 'components' describe('UseInput', () => { it('should follow change with use-input', () => { let log = '' const logSpy = jest.spyOn(console, 'log').mockImplementation(msg => (log = msg)) const MockInput...
2,841
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-keyboard/codes.ts
/** * KeyBinding Codes * The content of this file is based on the design of the open source project "microsoft/vscode", * Copyright (c) Microsoft Corporation. All rights reserved. * * We inherit the KeyMod values from "microsoft/vscode", * but use the Browser's KeyboardEvent event implementation, and all values...
2,842
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-keyboard/helper.ts
import { isMac } from '../utils/collections' import { KeyMod } from './codes' /* istanbul ignore next */ export const getCtrlKeysByPlatform = (): Record<string, 'metaKey' | 'ctrlKey'> => { return { CtrlCmd: isMac() ? 'metaKey' : 'ctrlKey', WinCtrl: isMac() ? 'ctrlKey' : 'metaKey', } } export const getActi...
2,843
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-keyboard/index.ts
import useKeyboard from './use-keyboard' import { KeyMod, KeyCode } from './codes' export { KeyMod, KeyCode } export type { UseKeyboardHandler, KeyboardOptions, KeyboardResult, UseKeyboard, } from './use-keyboard' export default useKeyboard
2,844
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-keyboard/use-keyboard.ts
import { KeyMod } from './codes' import React, { useEffect } from 'react' import { getActiveModMap, getCtrlKeysByPlatform } from './helper' export type KeyboardOptions = { disableGlobalEvent?: boolean stopPropagation?: boolean preventDefault?: boolean capture?: boolean event?: 'keydown' | 'keypress' | 'keyup...
2,845
0
petrpan-code/geist-org/geist-ui/components/use-keyboard
petrpan-code/geist-org/geist-ui/components/use-keyboard/__tests__/keyboard.test.tsx
import React from 'react' import { mount } from 'enzyme' import { useKeyboard, KeyMod, KeyCode } from 'components' import { renderHook, act } from '@testing-library/react-hooks' import { KeyboardResult } from '../use-keyboard' describe('UseKeyboard', () => { it('should work correctly', () => { let code = null ...
2,846
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-media-query/index.ts
import useMediaQuery from './use-media-query' export type { ResponsiveBreakpoint, ResponsiveOptions } from './use-media-query' export default useMediaQuery
2,847
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-media-query/use-media-query.ts
import { useEffect, useMemo, useState } from 'react' import useTheme from '../use-theme' import { tuple } from '../utils/prop-types' import { BreakpointsItem, GeistUIThemesBreakpoints } from '../themes/presets' const breakpoints = tuple('xs', 'sm', 'md', 'lg', 'xl', 'mobile') export type ResponsiveBreakpoint = typeof ...
2,848
0
petrpan-code/geist-org/geist-ui/components/use-media-query
petrpan-code/geist-org/geist-ui/components/use-media-query/__tests__/media-query.test.tsx
import { useMediaQuery } from 'components' import { renderHook } from '@testing-library/react-hooks' // @ts-ignore import mediaQuery from 'css-mediaquery' const mediaListMock = (width: number) => { ;(window as any).listeners = [] as Array<() => unknown> return (query: string) => { return { matches: media...
2,849
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-modal/index.ts
import useModal from './use-modal' export type { ModalHooksBindings } from './use-modal' export default useModal
2,850
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-modal/use-modal.ts
import { Dispatch, MutableRefObject, SetStateAction } from 'react' import useCurrentState from '../utils/use-current-state' import { ModalProps } from '../modal' export type ModalHooksBindings = Pick<ModalProps, 'visible' | 'onClose'> const useModal = ( initialVisible: boolean = false, ): { visible: boolean set...
2,851
0
petrpan-code/geist-org/geist-ui/components/use-modal
petrpan-code/geist-org/geist-ui/components/use-modal/__tests__/use-modal.test.tsx
import React, { useEffect } from 'react' import { mount, ReactWrapper } from 'enzyme' import { Modal, useModal } from 'components' import { updateWrapper } from 'tests/utils' export const expectModalIsOpened = (wrapper: ReactWrapper) => { expect(wrapper.find('.position').length).not.toBe(0) } export const expectMod...
2,852
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-scale/index.ts
import withScale from './with-scale' import { useScale } from './scale-context' export * from './utils' export * from './scale-context' export default useScale export { withScale }
2,853
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-scale/scale-context.ts
import React from 'react' export const ScalePropKeys = [ 'width', 'height', 'padding', 'margin', 'w', 'h', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'pl', 'pr', 'pt', 'pb', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'ml', 'mr', 'mt', 'mb', ...
2,854
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-scale/utils.ts
import { GetAllScalePropsFunction, GetScalePropsFunction, ScaleProps, ScalePropKeys, } from './scale-context' export const generateGetScaleProps = <P>( props: P & ScaleProps, ): GetScalePropsFunction => { const getScaleProps: GetScalePropsFunction = keyOrKeys => { if (!Array.isArray(keyOrKeys)) return ...
2,855
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-scale/with-scale.tsx
import React, { forwardRef } from 'react' import { DynamicLayoutPipe, ScaleConfig, ScaleContext, ScaleProps } from './scale-context' import useTheme from '../use-theme' import { isCSSNumberValue } from '../utils/collections' import { generateGetAllScaleProps, generateGetScaleProps } from './utils' const reduceScaleCoe...
2,856
0
petrpan-code/geist-org/geist-ui/components/use-scale
petrpan-code/geist-org/geist-ui/components/use-scale/__tests__/scale.test.tsx
import React from 'react' import useScale, { ScaleProps, ScaleConfig, withScale } from '../index' import { renderHook } from '@testing-library/react-hooks' import { mount } from 'enzyme' const BaseComponent: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => ( <div>{children}</div> ) const ScaleComponent...
2,857
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-tabs/index.ts
import useTabs from './use-tabs' export default useTabs
2,858
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-tabs/use-tabs.ts
import { Dispatch, MutableRefObject, SetStateAction } from 'react' import useCurrentState from '../utils/use-current-state' const useTabs = ( initialValue: string, ): { state: string setState: Dispatch<SetStateAction<string>> currentRef: MutableRefObject<string> bindings: { value: string onChange: (v...
2,859
0
petrpan-code/geist-org/geist-ui/components/use-tabs
petrpan-code/geist-org/geist-ui/components/use-tabs/__tests__/use-tabs.test.tsx
import React, { useEffect } from 'react' import { mount } from 'enzyme' import { Tabs, useTabs } from 'components' import { nativeEvent, updateWrapper } from 'tests/utils' describe('UseTabs', () => { it('should follow changes with use-tabs', async () => { const MockTabs: React.FC<{ value?: string }> = ({ value }...
2,860
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-theme/index.ts
import { useTheme } from './theme-context' export default useTheme
2,861
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-theme/theme-context.ts
import React from 'react' import Themes from '../themes' import { GeistUIThemes } from '../themes/presets' const defaultTheme = Themes.getPresetStaticTheme() export const ThemeContext: React.Context<GeistUIThemes> = React.createContext<GeistUIThemes>(defaultTheme) export const useTheme = (): GeistUIThemes => React....
2,862
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-toasts/helpers.tsx
import { Toast, ToastAction } from './use-toast' import React from 'react' import Button from '../button' import { GeistUIThemesPalette } from '../themes' import { NormalTypes, tuple } from '../utils/prop-types' export const makeToastActions = (actions: Toast['actions'], cancelHandle: () => void) => { const handler ...
2,863
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-toasts/index.ts
import useToasts from './use-toast' export type { ToastAction, Toast, ToastTypes, ToastInput, ToastLayout } from './use-toast' export default useToasts
2,864
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-toasts/toast-container.tsx
import React, { useEffect, useMemo } from 'react' import { createPortal } from 'react-dom' import usePortal from '../utils/use-portal' import useTheme from '../use-theme' import { useGeistUIContext } from '../utils/use-geist-ui-context' import ToastItem from './toast-item' import useClasses from '../use-classes' import...
2,865
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-toasts/toast-item.tsx
import React, { useMemo } from 'react' import useTheme from '../use-theme' import type { Toast, ToastLayout } from './use-toast' import CssTransition from '../shared/css-transition' import { makeToastActions, getColors, getTranslateByPlacement } from './helpers' export interface ToastItemProps { toast: Toast layou...
2,866
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/use-toasts/use-toast.tsx
import React, { CSSProperties, useEffect } from 'react' import type { NormalTypes } from '../utils/prop-types' import { defaultToastLayout, useGeistUIContext } from '../utils/use-geist-ui-context' import { getId } from '../utils/collections' import { ToastPlacement } from '../use-toasts/helpers' export interface Toast...
2,867
0
petrpan-code/geist-org/geist-ui/components/use-toasts
petrpan-code/geist-org/geist-ui/components/use-toasts/__tests__/index.test.tsx
import React from 'react' import { mount, ReactWrapper } from 'enzyme' import { useToasts, GeistProvider } from 'components' import { nativeEvent, updateWrapper } from 'tests/utils' import { ToastInput } from '../use-toast' const MockToast: React.FC<unknown> = () => { const { setToast } = useToasts() const clickHa...
2,868
0
petrpan-code/geist-org/geist-ui/components/use-toasts/__tests__
petrpan-code/geist-org/geist-ui/components/use-toasts/__tests__/__snapshots__/index.test.tsx.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`UseToast should render different actions 1`] = ` "<div class=\\"toasts\\"><div class=\\"toast toast-enter\\"><div class=\\"message\\">hello</div><div class=\\"action\\"><button type=\\"button\\" class=\\"btn\\"><div class=\\"text\\">remove</div><style> .bt...
2,869
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/user/index.ts
import User from './user' import UserLink from './user-link' export type UserComponentType = typeof User & { Link: typeof UserLink } ;(User as UserComponentType).Link = UserLink export type { UserProps } from './user' export default User as UserComponentType
2,870
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/user/user-link.tsx
import React from 'react' import Link from '../link' interface Props { href?: string className?: string } const defaultProps = { className: '', } type NativeAttrs = Omit<React.AnchorHTMLAttributes<any>, keyof Props> export type UserLinkProps = Props & NativeAttrs const UserLink = React.forwardRef< HTMLAncho...
2,871
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/user/user.tsx
import React, { ReactNode } from 'react' import Avatar from '../avatar' import useTheme from '../use-theme' import useScale, { withScale } from '../use-scale' import useClasses from '../use-classes' interface Props { name: ReactNode | string src?: string text?: string className?: string altText?: string } c...
2,872
0
petrpan-code/geist-org/geist-ui/components/user
petrpan-code/geist-org/geist-ui/components/user/__tests__/index.test.tsx
import React from 'react' import { mount, render } from 'enzyme' import { User } from 'components' describe(' User', () => { it('should render correctly', () => { const wrapper = mount(<User name="witt" />) expect(() => wrapper.unmount()).not.toThrow() }) it('should support image and text', () => { ...
2,873
0
petrpan-code/geist-org/geist-ui/components/user/__tests__
petrpan-code/geist-org/geist-ui/components/user/__tests__/__snapshots__/index.test.tsx.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[` User should support image and text 1`] = ` LoadedCheerio { "0": Node { "attribs": Object {}, "children": Array [ Node { "attribs": Object { "class": "user", }, "children": Array [ Node { "attrib...
2,874
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/calculations.ts
import { useMemo } from 'react' /** * Calculate the ratio of two numbers, maximum decimal length can be specified. * * (0, 100) => 0 * (50, 100) => 50 * (11.22, 100) => 11.22 * (11.22, 100, 4) => 11.2200 */ export const getProportions = ( value: number, max: number, maxFixed: number = 2, ): number => { ...
2,875
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/collections.ts
import React, { ReactNode } from 'react' export const getId = () => { return Math.random().toString(32).slice(2, 10) } export const capitalize = (str: string | symbol | number | undefined | null) => { const safeStr = String(str).trim() return safeStr.charAt(0).toUpperCase() + safeStr.slice(1) } export const ha...
2,876
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/color.ts
const hexToRgb = (color: string): [number, number, number] => { const fullReg = /^#?([a-f\d])([a-f\d])([a-f\d])$/i const full = color.replace(fullReg, (_, r, g, b) => `${r}${r}${g}${g}${b}${b}`) const values = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(full) if (!values) { throw new Error(`Geist UI: U...
2,877
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/layouts.ts
import { MouseEvent, FocusEvent, MutableRefObject, useState } from 'react' export const getElementOffset = (el?: HTMLElement | null | undefined) => { if (!el) return { top: 0, left: 0, } const { top, left } = el.getBoundingClientRect() return { top, left } } export interface ReactiveDomReact...
2,878
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/prop-types.ts
export const tuple = <T extends string[]>(...args: T) => args export const tupleNumber = <T extends number[]>(...args: T) => args const buttonTypes = tuple( 'default', 'secondary', 'success', 'warning', 'error', 'abort', 'secondary-light', 'success-light', 'warning-light', 'error-light', ) const ...
2,879
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/types.ts
export type DeepPartial<T> = { [P in keyof T]?: T[P] extends Record<string, any> ? DeepPartial<T[P]> : T[P] }
2,880
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-body-scroll.ts
import useBodyScroll from '../use-body-scroll' export default useBodyScroll
2,881
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-click-anywhere.ts
import { useEffect } from 'react' const useClickAnyWhere = (handler: (event: Event) => void) => { useEffect(() => { const callback = (event: Event) => handler(event) document.addEventListener('click', callback) return () => document.removeEventListener('click', callback) }, [handler]) } export defaul...
2,882
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-click-away.ts
import { default as useClickAway } from '../use-click-away' export default useClickAway
2,883
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-clipboard.ts
import useClipboard from '../use-clipboard' export default useClipboard
2,884
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-current-state.ts
import useCurrentState from '../use-current-state' export default useCurrentState
2,885
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-default-props.ts
const useDefaultProps = <T extends Record<string | number, any>, D extends Partial<T>>( props: T, defaultProps: D, ): T & Required<D> => { let nextProps = {} as T const propsKeys: Array<keyof T> = Object.keys(props || {}) const defaultKeys: Array<keyof T> = Object.keys(defaultProps || {}) for (const propsN...
2,886
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-dom-observer.ts
import { MutableRefObject, useEffect } from 'react' const useDOMObserver = ( ref: MutableRefObject<HTMLElement | null> | undefined, callback: MutationCallback = () => {}, ) => { const config = { attributes: false, childList: true, subtree: true } useEffect(() => { if (!ref || !ref.current) return let ...
2,887
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-drag.ts
import { RefObject, useEffect, useRef } from 'react' import useCurrentState from './use-current-state' export type DraggingEvent = { startX: number currentX: number } export type DraggingHandler = (event: DraggingEvent) => void const useDrag = ( elementRef: RefObject<HTMLElement> | null, draggingHandler: Dra...
2,888
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-geist-ui-context.ts
import React from 'react' import type { ToastLayout, Toast } from '../use-toasts/use-toast' export const defaultToastLayout: Required<ToastLayout> = { padding: '12px 16px', margin: '8px 0', width: '420px', maxWidth: '90vw', maxHeight: '75px', placement: 'bottomRight', } export type UpdateToastsFunction = ...
2,889
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-portal.ts
import { useEffect, useState } from 'react' import useSSR from '../utils/use-ssr' import { getId } from './collections' const createElement = (id: string): HTMLElement => { const el = document.createElement('div') el.setAttribute('id', id) return el } const usePortal = ( selectId: string = getId(), getConta...
2,890
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-previous.ts
import { useEffect, useRef } from 'react' const usePrevious = <T>(state: T): T | undefined | null => { const ref = useRef<T | null>(null) useEffect(() => { ref.current = state }) return ref ? ref.current : null } export default usePrevious
2,891
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-real-shape.ts
import { MutableRefObject, useEffect, useState } from 'react' export type ShapeType = { width: number height: number } export const getRealShape = (el: HTMLElement | null): ShapeType => { const defaultShape: ShapeType = { width: 0, height: 0 } if (!el || typeof window === 'undefined') return defaultShape c...
2,892
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-resize.ts
import { useEffect } from 'react' const useResize = (callback: () => unknown, immediatelyInvoke: boolean = true): void => { useEffect(() => { const fn = () => callback() if (immediatelyInvoke) { fn() } window.addEventListener('resize', fn) return () => window.removeEventListener('resize', f...
2,893
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-ssr.ts
import { useEffect, useState } from 'react' import { isBrowser } from './collections' export type SSRState = { isBrowser: boolean isServer: boolean } const useSSR = (): SSRState => { const [browser, setBrowser] = useState<boolean>(false) useEffect(() => { setBrowser(isBrowser()) }, []) return { i...
2,894
0
petrpan-code/geist-org/geist-ui/components
petrpan-code/geist-org/geist-ui/components/utils/use-warning.ts
const warningStack: { [key: string]: boolean } = {} const useWarning = (message: string, component?: string) => { const tag = component ? ` [${component}]` : ' ' const log = `[Geist UI]${tag}: ${message}` if (typeof console === 'undefined') return if (warningStack[log]) return warningStack[log] = true if...
2,895
0
petrpan-code/geist-org/geist-ui/components/utils
petrpan-code/geist-org/geist-ui/components/utils/__tests__/calculations.test.tsx
import React from 'react' import { mount } from 'enzyme' import { getProportions, useProportions } from '../calculations' describe('calculations', () => { it('should return ratio and limit the length of decimals', () => { expect(getProportions(0, 100)).toEqual(0) expect(getProportions(50, 100)).toEqual(50) ...
2,896
0
petrpan-code/geist-org/geist-ui/components/utils
petrpan-code/geist-org/geist-ui/components/utils/use-context-state/create-geist-context.tsx
import React, { useImperativeHandle } from 'react' import useContextState, { ContextHandler, ContextHandlerWhere, ContextStateFilter, ContextStateOnChange, ContextStates, } from './use-context-state' import { capitalize } from '../collections' const makeVirtualValues = <S,>(values: S): ContextStates<S> => { ...
2,897
0
petrpan-code/geist-org/geist-ui/components/utils
petrpan-code/geist-org/geist-ui/components/utils/use-context-state/use-context-state.ts
import { Dispatch, MutableRefObject, SetStateAction, useMemo } from 'react' import useCurrentState from '../use-current-state' import { capitalize } from '../collections' export type ContextStateOnChange<T> = <K extends keyof T>(key: K, nextValue: T[K]) => void export type ContextHandler<S> = { [K in keyof S as `set...
2,898
0
petrpan-code/geist-org/geist-ui/examples
petrpan-code/geist-org/geist-ui/examples/create-next-app/.eslintrc.json
{ "extends": "next/core-web-vitals" }
2,899