Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Remove "extras" from generated component
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Laco committed Oct 3, 2018
1 parent a85251f commit 609540f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 86 deletions.
6 changes: 0 additions & 6 deletions commands/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ module.exports = async function (context) {
{
template: 'component.tsx.ejs',
target: `src/views/${domainPath}${name}/${name}.tsx`
}, {
template: 'component.presets.ts.ejs',
target: `src/views/${domainPath}${name}/${name}.presets.ts`
}, {
template: 'component.props.ts.ejs',
target: `src/views/${domainPath}${name}/${name}.props.ts`
}, {
template: 'component.story.tsx.ejs',
target: `src/views/${domainPath}${name}/${name}.story.tsx`
Expand Down
45 changes: 0 additions & 45 deletions templates/component.presets.ts.ejs

This file was deleted.

24 changes: 0 additions & 24 deletions templates/component.props.ts.ejs

This file was deleted.

37 changes: 26 additions & 11 deletions templates/component.tsx.ejs
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
import * as React from "react"
import { TouchableOpacity } from "react-native"
import { ViewStyle, TouchableOpacity } from "react-native"
<% if (props.newDomain) { -%>
import { Text } from "../shared/text"
<% } else if (props.sharedComponent) { -%>
import { Text } from "../text"
<% } else { -%>
import { Text } from "../../shared/text"
<% } -%>
import { viewPresets, textPresets } from "./<%= props.name %>.presets"
import { <%= props.pascalName %>Props } from "./<%= props.name %>.props"

export interface <%= props.pascalName %>Props extends TouchableOpacityProperties {
/**
* Text which is looked up via i18n.
*/
tx?: string

/**
* The text to display if not using `tx` or nested components.
*/
text?: string

/**
* An optional style override useful for padding & margin.
*/
style?: ViewStyle

/**
* One of the different types of text presets.
*/
preset?: <%= props.pascalName %>PresetNames
}

/**
* Stateless functional component for your needs
*
* Component description here for TypeScript tips.
*/
export function <%= props.pascalName %>(props: <%= props.pascalName %>Props) {
// grab the props
const { preset = "primary", tx, text, style: styleOverride, ...rest } = props

// assemble the style
const viewPresetToUse = viewPresets[preset] || viewPresets.primary
const textPresetToUse = textPresets[preset] || textPresets.primary

const viewStyle = { ...viewPresetToUse, ...styleOverride }
const textStyle = textPresetToUse
const { tx, text, style, ...rest } = props
const textStyle = { }

return (
<TouchableOpacity style={viewStyle} {...rest}>
<TouchableOpacity style={style} {...rest}>
<Text tx={tx} text={text} style={textStyle} />
</TouchableOpacity>
)
Expand Down

0 comments on commit 609540f

Please sign in to comment.