Skip to content

Commit

Permalink
chore: draft for component help
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-ivanovvv committed May 14, 2024
1 parent da05e48 commit 7b89c4f
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 29 deletions.
7 changes: 4 additions & 3 deletions app/entrypoints/renderer/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import { ThemeProvider } from '@ui/theme'
import { Input } from '@ui/input'
import { BaseSwitch } from '@ui/switch'
import { IconSwitch } from '@ui/switch'
import { ModeSwitch } from '@ui/switch'
import { ThemeSwitch } from '@ui/switch'
import { TelegramIcon } from '@ui/icons-test'

Check failure on line 10 in app/entrypoints/renderer/src/app/page.tsx

View workflow job for this annotation

GitHub Actions / Lint

(@typescript-eslint/no-unused-vars): 'ThemeSwitch' is defined but never used.

'ThemeSwitch' is defined but never used.
Raw output
   7 | import { BaseSwitch }        from '@ui/switch'
   8 | import { IconSwitch }        from '@ui/switch'
>  9 | import { ThemeSwitch }        from '@ui/switch'
     |          ^
  10 | import { TelegramIcon }      from '@ui/icons-test'
  11 |
  12 | const Page = () => (

const Page = () => (
<ThemeProvider>
<Input placeholder='placeholder' />
<BaseSwitch />
<IconSwitch />
<TelegramIcon width={24} height={24} />
<IconSwitch>
<TelegramIcon width={16} height={16} />
</IconSwitch>
</ThemeProvider>
)

Expand Down
15 changes: 9 additions & 6 deletions ui/switch/src/icon/icon.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import styled from '@emotion/styled'
import { HandleElement } from '@atls-ui-parts/switch'
import { baseHandleStyles } from '@atls-ui-parts/switch'
import { useSwitch } from '@atls-ui-parts/switch'
import { baseThumbStyles } from '@atls-ui-parts/switch'
import { ifDisabledThumbModifier } from '@atls-ui-parts/switch'

import React from 'react'
import { useRef } from 'react'
import { useHover } from 'react-laag'

import { IconProps } from './icon.interfaces'
import { IconSwitchProps } from './icon.interfaces'

import { ThumbElement } from './thumb/thumb.element'

import { appearanceHandleStyles } from './icon.styles'
import { appearanceThumbStyles } from './icon.styles'
import { shapeThumbStyles } from './icon.styles'
import { shapeHandleStyles } from './icon.styles'
import { baseThumbStyles } from './icon.styles'
import { shapeThumbStyles } from './icon.styles'
import { appearanceThumbStyles } from './icon.styles'


const Thumb = styled(ThumbElement)<any>(
baseThumbStyles,
Expand All @@ -36,7 +37,7 @@ const thumbMotionVariants = {

const Element = styled(HandleElement)(baseHandleStyles, appearanceHandleStyles, shapeHandleStyles)

const IconSwitch = ({ disabled, checked: defaultValue, onChange }: IconProps) => {
const IconSwitch = ({ disabled, checked: defaultValue, onChange, children }: IconSwitchProps) => {
const node = useRef<HTMLButtonElement>(null)
const [hover, hoverProps] = useHover()
const [checked, setChecked] = useSwitch(node, defaultValue, disabled, onChange)
Expand All @@ -49,7 +50,9 @@ const IconSwitch = ({ disabled, checked: defaultValue, onChange }: IconProps) =>
variants={{
...thumbMotionVariants,
}}
/>
>
{children}
</Thumb>
</Element>
)
}
Expand Down
4 changes: 2 additions & 2 deletions ui/switch/src/icon/icon.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SwitchProps } from '@atls-ui-parts/switch'

export interface IconSwitchProps extends SwitchProps {
// TODO make it icon props
icon?: any
// TODO make it icon type
children: any
}
8 changes: 8 additions & 0 deletions ui/switch/src/icon/icon.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { styleFn } from 'styled-system'
import { ifProp } from 'styled-tools'
import { switchProp } from 'styled-tools'
import { prop } from 'styled-tools'
import { baseThumbStyles as hyperionBaseThumbStyles } from '@atls-ui-parts/switch'

export const appearanceDefaultHandleStyles: styleFn = ({ theme }) => ({
backgroundColor: theme.colors.switch.icon.default.background,
Expand Down Expand Up @@ -38,6 +39,13 @@ export const shapeNormalSizeHandleStyles: styleFn = () => ({
height: 28,
})

export const baseThumbStyles: styleFn = () => ({
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
...hyperionBaseThumbStyles
})

export const shapeNormalSizeThumbStyles: styleFn = () => ({
width: 24,
height: 24,
Expand Down
20 changes: 9 additions & 11 deletions ui/switch/src/icon/thumb/thumb.element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ import { FunctionComponent } from 'react'
import { motion } from 'framer-motion'
import { useMemo } from 'react'

export const thumbMotionVariants = {
visible: {
left: 0,
},
checked: {
left: 16,
},
}

const ThumbElement: FunctionComponent<ThumbElementProps> = ({ checked, ...props }) => {
const ThumbElement: FunctionComponent<ThumbElementProps> = ({ checked, children, ...props }) => {
const initial = useMemo(() => (checked ? 'checked' : 'visible'), [checked])

return <motion.span initial={initial} animate={checked ? 'checked' : 'visible'} {...props} />
// TODO уточни этот момент

const color = checked ? 'white' : 'black'
return (

Check failure on line 14 in ui/switch/src/icon/thumb/thumb.element.tsx

View workflow job for this annotation

GitHub Actions / Lint

(@typescript-eslint/no-unused-vars): 'color' is assigned a value but never used.

'color' is assigned a value but never used.
Raw output
  11 | 	// TODO уточни этот момент
  12 |
> 13 | 	const color = checked ? 'white' : 'black'
     | 	      ^
  14 |   return (
  15 | 	<motion.span initial={initial} animate={checked ? 'checked' : 'visible'} {...props} >
  16 | 		{children}
<motion.span initial={initial} animate={checked ? 'checked' : 'visible'} {...props} >
{children}
</motion.span>
)
}

export { ThumbElement }
2 changes: 1 addition & 1 deletion ui/switch/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './base'
export * from './icon'
export * from './mode'
export * from './theme'
2 changes: 0 additions & 2 deletions ui/switch/src/mode/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions ui/switch/src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './theme.component'
export * from './theme.interfaces'
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { useHover } from 'react-laag'

import { ToggleProps } from './icon.interfaces'
import { ThumbElement } from './thumb/thumb.element'
import { appearanceHandleStyles } from './mode.styles'
import { appearanceThumbStyles } from './mode.styles'
import { shapeThumbStyles } from './mode.styles'
import { shapeHandleStyles } from './mode.styles'
import { appearanceHandleStyles } from './theme.styles'
import { appearanceThumbStyles } from './theme.styles'
import { shapeThumbStyles } from './theme.styles'
import { shapeHandleStyles } from './theme.styles'

const Thumb = styled(ThumbElement)<any>(
baseThumbStyles,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7b89c4f

Please sign in to comment.