Skip to content
Merged
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
5 changes: 3 additions & 2 deletions example/src/views/speedDial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default () => {
<Header title="Speed Dial" view="speeddial" />
<SpeedDial
isOpen={open}
// placement="right"
// isOpen={false}
labelPressable
placement="right"
overlayColor="transparent"
icon={{ name: 'edit', color: '#fff' }}
openIcon={{ name: 'close', color: '#fff' }}
Expand All @@ -37,6 +37,7 @@ export default () => {
openIcon={{ name: 'close', color: '#fff' }}
onOpen={() => setOpen(!open)}
onClose={() => setOpen(!open)}
labelPressable
>
<SpeedDial.Action
icon={{ name: 'add', color: '#fff' }}
Expand Down
21 changes: 16 additions & 5 deletions packages/base/src/SpeedDial/SpeedDial.Action.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { Pressable, Text, StyleSheet } from 'react-native';
import { FAB, FABProps } from '../FAB/index';
import { RneFunctionComponent } from '../helpers';

export interface SpeedDialActionProps extends Omit<FABProps, 'size'> {}
export interface SpeedDialActionProps extends Omit<FABProps, 'size'> {
/** onPress on Label Press */
labelPressable?: boolean;
}

/** Adds Action to the SpeedDial.
* This, Receive all [Fab](fab#props) props. */
export const SpeedDialAction: RneFunctionComponent<SpeedDialActionProps> = ({
title,
titleStyle,
placement,
labelPressable,
onPress,
...actionProps
}) => {
return (
<View
<Pressable
onPress={labelPressable ? onPress : undefined}
style={[
styles.action,
placement === 'left' && {
Expand All @@ -23,8 +29,13 @@ export const SpeedDialAction: RneFunctionComponent<SpeedDialActionProps> = ({
]}
>
{title && <Text style={[styles.title, titleStyle]}>{title}</Text>}
<FAB {...actionProps} size="small" style={[actionProps.style]} />
</View>
<FAB
{...actionProps}
onPress={onPress}
size="small"
style={[actionProps.style]}
/>
</Pressable>
);
};

Expand Down
11 changes: 10 additions & 1 deletion packages/base/src/SpeedDial/SpeedDial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FAB, FABProps } from '../FAB';
import { IconNode } from '../Icon';
import Color from 'color';
import { defaultTheme, RneFunctionComponent } from '../helpers';
import { SpeedDialActionProps } from './SpeedDial.Action';

export interface SpeedDialProps extends FABProps {
/** Opens the action stack. */
Expand Down Expand Up @@ -39,6 +40,9 @@ export interface SpeedDialProps extends FABProps {

/** Props for Backdrop Pressable */
backdropPressableProps?: PressableProps;

/** onPress on Label Press for all Actions*/
labelPressable?: boolean;
}

/** When pressed, a floating action button can display three to six related actions in the form of a speed dial.
Expand All @@ -58,6 +62,7 @@ export const SpeedDial: RneFunctionComponent<SpeedDialProps> = ({
overlayColor,
theme = defaultTheme,
placement,
labelPressable,
backdropPressableProps: pressableProps,
...rest
}) => {
Expand Down Expand Up @@ -118,7 +123,10 @@ export const SpeedDial: RneFunctionComponent<SpeedDialProps> = ({
]}
>
{React.Children.toArray(children).map(
(ChildAction: React.ReactElement, i: number) => (
(
ChildAction: React.ReactElement<SpeedDialActionProps>,
i: number
) => (
<Animated.View
pointerEvents={isOpen ? 'auto' : 'none'}
key={i}
Expand All @@ -129,6 +137,7 @@ export const SpeedDial: RneFunctionComponent<SpeedDialProps> = ({
>
{React.cloneElement(ChildAction, {
placement,
labelPressable,
})}
</Animated.View>
)
Expand Down
20 changes: 20 additions & 0 deletions packages/base/src/SpeedDial/__tests__/SpeedDial.Action.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { fireEvent } from '@testing-library/react-native';
import { SpeedDial } from '..';
import { renderWithWrapper } from '../../../.ci/testHelper';

describe('Speed Dial Action', () => {
it('should have onPress event', () => {
const onPress = jest.fn();
const { getByText } = renderWithWrapper(
<SpeedDial.Action
icon={{ name: 'delete', color: '#fff' }}
title="Delete"
onPress={onPress}
/>
);
const title = getByText('Delete');
fireEvent(title, 'press');
expect(onPress).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ exports[`Speed Dial Component should match snapshot 1`] = `
}
>
<View
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand Down Expand Up @@ -269,6 +281,18 @@ exports[`Speed Dial Component should match snapshot 1`] = `
}
>
<View
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ exports[`Speed Dial Component should render 1`] = `
}
>
<View
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand Down Expand Up @@ -269,6 +281,18 @@ exports[`Speed Dial Component should render 1`] = `
}
>
<View
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand Down
8 changes: 8 additions & 0 deletions website/docs/components/SpeedDial.Action.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ This, Receive all [Fab](fab#props) props.
:::note
Includes all [FAB](fab#props) props.
:::

<div class='table-responsive'>

| Name | Type | Default | Description |
| ---------------- | ------- | ------- | ---------------------- |
| `labelPressable` | boolean | | onPress on Label Press |

</div>
1 change: 1 addition & 0 deletions website/docs/components/SpeedDial.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Includes all [Button](button#props), [FAB](fab#props) props.
| `backdropPressableProps` | PressableProps | | Props for Backdrop Pressable |
| `children` | SpeedDial.Action | | SpeedDial Action as children. |
| `isOpen` | boolean | `false` | Opens the action stack. |
| `labelPressable` | boolean | | onPress on Label Press for all Actions |
| `onClose` | Function | `Function` | Callback fired when the component requests to be closed. |
| `onOpen` | Function | `Function` | Callback fired when the component requests to be open. |
| `openIcon` | IconNode | | Icon shown on FAB when action stack is open. |
Expand Down