-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
104 additions
and
38 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react' | ||
|
||
import Button from '.'; | ||
|
||
describe('Button', () => { | ||
it('renders non-themed', () => { | ||
render(<Button onClick={jest.fn()} text="mario" name="signupButton" />); | ||
expect(screen.getByRole('button').className).toEqual('nile'); | ||
}) | ||
it('renders themed string', () => { | ||
render(<Button onClick={jest.fn()} text="mario" name="signupButton" />); | ||
expect(screen.getByRole('button').className).toEqual('nile'); | ||
}) | ||
it('renders themed component', () => { | ||
render(<Button onClick={jest.fn()} text="mario" name="signupButton" />); | ||
expect(screen.getByRole('button').className).toEqual('nile'); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import React from 'react'; | ||
import { useTheme } from '../../theme'; | ||
|
||
type ButtonProps = { | ||
type?: 'button' | 'submit' | 'reset'; | ||
children: string; | ||
onClick?: () => void; | ||
name: 'signupButton'; | ||
text: string; | ||
}; | ||
|
||
export default function Button(props: ButtonProps) { | ||
const { type, children, onClick } = props; | ||
const { type, text, onClick, name } = props; | ||
const theme = useTheme(name); | ||
if (typeof theme === 'function') { | ||
return <>{theme}</> | ||
} | ||
|
||
|
||
return ( | ||
<button type={type ?? 'button'} onClick={onClick}> | ||
{children} | ||
<button className={theme} type={type ?? 'button'} onClick={onClick} role="button"> | ||
{text} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
import React from 'react'; | ||
|
||
import { useTheme, InputThemeName } from '../../theme'; | ||
|
||
export function Input({ name }: { name: InputThemeName }) { | ||
const theme = useTheme(name); | ||
if (typeof theme === 'function') { | ||
return <>{theme}</> | ||
} | ||
|
||
return <input className={theme} type="text" placeholder={name} id={name} > </input> | ||
|
||
} | ||
|
||
export function Label({ htmlFor, text }: { text: string, htmlFor: InputThemeName}) { | ||
|
||
const theme = useTheme(htmlFor); | ||
if (typeof theme === 'function') { | ||
return <>{theme}</> | ||
} | ||
|
||
return <label className={theme} htmlFor={htmlFor}>{text}</label> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import {NileService} from '@theniledev/js'; | ||
import { NileService } from '@theniledev/js'; | ||
import React from 'react'; | ||
import { Theme } from '../global-types' | ||
|
||
export interface NileContext { | ||
instance: NileService; | ||
theme: Theme | string | ||
} | ||
|
||
export interface NileProviderProps { | ||
children: React.ReactNode; | ||
apiUrl: string; | ||
theme: Theme | string, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
export interface Theme { | ||
email?: React.ReactNode | ||
password?: React.ReactNode | ||
signupButton?: React.ReactNode | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useMemo } from 'react'; | ||
import { useNileContextTheme } from '../context'; | ||
|
||
|
||
const ThemeConfig = { | ||
'email': 'email', | ||
'password': 'password', | ||
'signupButton': 'signupButton' | ||
} | ||
export type InputThemeName = 'email' | 'password' | 'signupButton'; | ||
|
||
export const useTheme = (name: InputThemeName) => { | ||
const contextTheme = useNileContextTheme(); | ||
const override = typeof contextTheme === 'object' && contextTheme[name]; | ||
return useMemo(() => { | ||
if (typeof override === 'function') { | ||
return override; | ||
} | ||
return `${contextTheme}-${ThemeConfig[name]}`; | ||
}, [name]); | ||
}; |