Skip to content

Commit

Permalink
fix: warnings from styled-components on language input render (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars authored Dec 16, 2024
1 parent e6af22b commit 4c71607
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/LanguageField.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import {useCallback} from 'react'
import {FieldMember, InputProps, MemberField, MemberFieldProps, StringInputProps} from 'sanity'
import {
FieldMember,
type InputProps,
MemberField,
type MemberFieldProps,
type PrimitiveInputElementProps,
} from 'sanity'

import {LanguageInput} from './LanguageInput'
import {CodeInputLanguage} from './types'
import type {CodeInputLanguage} from './types'

export function LanguageField(

Check warning on line 13 in src/LanguageField.tsx

View workflow job for this annotation

GitHub Actions / Lint & Build

Missing return type on function

Check warning on line 13 in src/LanguageField.tsx

View workflow job for this annotation

GitHub Actions / Lint & Build

Missing return type on function
props: MemberFieldProps & {member: FieldMember; language: string; languages: CodeInputLanguage[]},
) {
const {member, languages, language, renderItem, renderField, renderPreview} = props

const renderInput = useCallback(
(inputProps: Omit<InputProps, 'renderDefault'>) => {
({elementProps, onChange}: Omit<InputProps, 'renderDefault'>) => {
return (
<LanguageInput
{...(inputProps as StringInputProps)}
onChange={onChange}
elementProps={elementProps as PrimitiveInputElementProps}
language={language}
languages={languages}
/>
Expand Down
12 changes: 7 additions & 5 deletions src/LanguageInput.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import {Select} from '@sanity/ui'
import {ChangeEvent, useCallback} from 'react'
import {set, StringInputProps, unset} from 'sanity'
import {type ChangeEvent, useCallback} from 'react'
import {set, type StringInputProps, unset} from 'sanity'

import {CodeInputLanguage} from './types'

export interface LanguageInputProps extends StringInputProps {
export interface LanguageInputProps {
language: string
languages: CodeInputLanguage[]
onChange: StringInputProps['onChange']
elementProps: StringInputProps['elementProps']
}

/** @internal */
export function LanguageInput(props: LanguageInputProps) {

Check warning on line 15 in src/LanguageInput.tsx

View workflow job for this annotation

GitHub Actions / Lint & Build

Missing return type on function

Check warning on line 15 in src/LanguageInput.tsx

View workflow job for this annotation

GitHub Actions / Lint & Build

Missing return type on function
const {language, languages, onChange} = props
const {language, languages, onChange, elementProps} = props

const handleChange = useCallback(
(e: ChangeEvent<HTMLSelectElement>) => {
Expand All @@ -22,7 +24,7 @@ export function LanguageInput(props: LanguageInputProps) {
)

return (
<Select {...props} value={language} onChange={handleChange}>
<Select {...elementProps} value={language} onChange={handleChange}>
{languages.map((lang: {title: string; value: string}) => (
<option key={lang.value} value={lang.value}>
{lang.title}
Expand Down

0 comments on commit 4c71607

Please sign in to comment.