Skip to content

Feat/ Add custom content to Hint #1302

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

Merged
merged 2 commits into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 30 additions & 10 deletions demo/src/screens/componentScreens/HintsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React, {Component} from 'react';
import {Alert} from 'react-native';
import {View, Text, Hint, Button, RadioGroup, RadioButton, Switch} from 'react-native-ui-lib'; //eslint-disable-line

const settingsIcon = require('../../assets/icons/settings.png');

type HintScreenProps = {};
type HintScreenState = {
showHint: boolean,
useShortMessage: boolean,
showBottomHint: boolean,
showIcon: boolean,
targetPosition: string,
useTargetFrame?: boolean,
useSideTip?: boolean
showHint: boolean;
useShortMessage: boolean;
showBottomHint: boolean;
showIcon: boolean;
targetPosition: string;
useTargetFrame?: boolean;
useSideTip?: boolean;
showCustomContent?: boolean;
};

export default class HintsScreen extends Component<HintScreenProps, HintScreenState> {
Expand All @@ -24,7 +26,8 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
showIcon: false,
targetPosition: 'flex-start',
// useTargetFrame: true,
useSideTip: false
useSideTip: false,
showCustomContent: false
};
}

Expand All @@ -44,7 +47,8 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
targetPosition,
useShortMessage,
useSideTip,
useTargetFrame
useTargetFrame,
showCustomContent
} = this.state;
const targetFrame = {x: 140, y: 100, width: 10, height: 10};
const message = useShortMessage
Expand All @@ -56,7 +60,7 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
<View
flex
padding-20
paddingT-120
paddingT-100
bg-dark80
style={{zIndex: 10}}
key={useTargetFrame ? 'withTargetFrame' : 'withElement'}
Expand Down Expand Up @@ -85,6 +89,17 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
// borderRadius={BorderRadiuses.br40}
// edgeMargins={30}
// onBackgroundPress={() => this.setState({showHint: !showHint})}
customContent={
showCustomContent ? (
<Text text70 white>
Click
<Text onPress={() => Alert.alert('custom content :)')} text70BO violet50>
{' here '}
</Text>
for more information
</Text>
) : undefined
}
testID={'Hint'}
>
{!useTargetFrame && (
Expand Down Expand Up @@ -158,6 +173,11 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
<Switch value={useTargetFrame} onValueChange={value => this.setState({useTargetFrame: value})}/>
<Text marginL-10>Use random position</Text>
</View>

<View row centerV marginV-10>
<Switch value={showCustomContent} onValueChange={value => this.setState({showCustomContent: value})}/>
<Text marginL-10>Show custom content</Text>
</View>
</View>
</View>
);
Expand Down
4 changes: 4 additions & 0 deletions generatedTypes/components/hint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export interface HintProps {
* The hint container width
*/
containerWidth?: number;
/**
* Custom content element to render inside the hint container
*/
customContent?: JSX.Element;
/**
* The hint's test identifier
*/
Expand Down
11 changes: 8 additions & 3 deletions src/components/hint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ export interface HintProps {
* The hint container width
*/
containerWidth?: number;
/**
* Custom content element to render inside the hint container
*/
customContent?: JSX.Element;
/**
* The hint's test identifier
*/
Expand Down Expand Up @@ -411,7 +415,7 @@ class Hint extends Component<HintProps, HintState> {
}

renderHint() {
const {message, messageStyle, icon, iconStyle, borderRadius, color, testID} = this.props;
const {message, messageStyle, icon, iconStyle, borderRadius, color, customContent, testID} = this.props;

if (this.showHint) {
return (
Expand All @@ -435,8 +439,9 @@ class Hint extends Component<HintProps, HintState> {
style={[styles.hint, color && {backgroundColor: color}, !_.isUndefined(borderRadius) && {borderRadius}]}
ref={this.setHintRef}
>
{icon && <Image source={icon} style={[styles.icon, iconStyle]}/>}
<Text style={[styles.hintMessage, messageStyle]}>{message}</Text>
{customContent}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding a renderContent method?

{!customContent && icon && <Image source={icon} style={[styles.icon, iconStyle]}/>}
{!customContent && <Text style={[styles.hintMessage, messageStyle]}>{message}</Text>}
</View>
</View>
);
Expand Down