Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warnings from styled-components on language input render #112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
const {language, languages, onChange} = props
const {language, languages, onChange, elementProps} = props

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

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
Loading