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
21 changes: 21 additions & 0 deletions packages/base/src/hooks/useConsolidatedRef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { RefObject, useEffect, useMemo, useRef } from 'react';

export const useConsolidatedRef = <T>(ref): RefObject<T> => {
const localPopoverRef: RefObject<T> = useRef(null);

const consolidatedRef = useMemo(() => {
if (!ref || typeof ref === 'function') {
return localPopoverRef;
}
return ref;
}, [ref]);

useEffect(() => {
if (typeof ref === 'function') {
// @ts-ignore
ref(consolidatedRef.current);
}
}, [consolidatedRef.current]);

return consolidatedRef;
};
4 changes: 3 additions & 1 deletion packages/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Optional from './Optional';
import StyleClassHelper from './StyleClassHelper';
import { deprecationNotice, pushElementBackInScreen } from './Util';
import { createGenerateClassName } from './withStyles/createGenerateClassName';
import { useConsolidatedRef } from './hooks/useConsolidatedRef';

export {
StyleClassHelper,
Expand All @@ -36,5 +37,6 @@ export {
sap_fiori_3,
bootstrap,
withStyles,
createGenerateClassName
createGenerateClassName,
useConsolidatedRef
};
5 changes: 4 additions & 1 deletion packages/base/src/withStyles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
import React, { ComponentType, ForwardRefExoticComponent, RefAttributes, RefObject } from 'react';
// @ts-ignore
import { createUseStyles, useTheme } from 'react-jss';
import { useConsolidatedRef } from '../hooks/useConsolidatedRef';

const getDisplayName = (Component) => Component.displayName || Component.name || 'Component';
const wrapComponentName = (componentName) => `WithStyles(${componentName})`;
Expand All @@ -22,7 +23,9 @@ export function withStyles<T>(styles): any {
const classes = useStyles(props);
const theme = useTheme();

return <Component {...props} ref={ref} classes={classes} theme={theme} />;
const consolidatedRef = useConsolidatedRef(ref);

return <Component {...props} innerRef={consolidatedRef} classes={classes} theme={theme} />;
});

WithStyles.defaultProps = Component.defaultProps;
Expand Down
1 change: 1 addition & 0 deletions packages/charts/src/interfaces/CommonProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface CommonProps {
* A tooltip which will be shown on hover
*/
tooltip?: string;
slot?: string;
}
30 changes: 14 additions & 16 deletions packages/main/__karma_snapshots__/ActionSheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@
<ThemeProvider withToastContainer={false}>
<JssProvider generateId={[Function]} id={{...}}>
<ThemeProvider theme={{...}}>
<WithStyles(ActionSheet) openBy={{...}} placement="Bottom">
<ActionSheet openBy={{...}} placement="Bottom" classes={{...}} theme={{...}}>
<Popover openBy={{...}} placementType="Bottom" style={[undefined]} slot={[undefined]} initialFocus={{...}} headerText="" horizontalAlign="Center" verticalAlign="Center">
<div style={{...}} onClick={[Function]}>
<Button design="Default">
<ui5-button design="Default" class="" />
</Button>
</div>
<WithWebComponent(Popover) placementType="Bottom" style={[undefined]} slot={[undefined]} initialFocus={{...}} headerText="" horizontalAlign="Center" verticalAlign="Center">
<ui5-popover placement-type="Bottom" style={[undefined]} slot={[undefined]} initial-focus={{...}} header-text="" horizontal-align="Center" vertical-align="Center" class="">
<ul className="ActionSheet-actionSheet---" />
</ui5-popover>
</WithWebComponent(Popover)>
</Popover>
</ActionSheet>
</WithStyles(ActionSheet)>
<ActionSheet openBy={{...}} placement="Bottom">
<Popover openBy={{...}} placementType="Bottom" style={[undefined]} slot={[undefined]} initialFocus={{...}} headerText="" horizontalAlign="Center" verticalAlign="Center">
<div style={{...}} onClick={[Function]}>
<Button design="Default">
<ui5-button design="Default" class="" />
</Button>
</div>
<WithWebComponent(Popover) placementType="Bottom" style={[undefined]} slot={[undefined]} initialFocus={{...}} headerText="" horizontalAlign="Center" verticalAlign="Center">
<ui5-popover placement-type="Bottom" style={[undefined]} slot={[undefined]} initial-focus={{...}} header-text="" horizontal-align="Center" vertical-align="Center" class="">
<ul className="-actionSheet---" />
</ui5-popover>
</WithWebComponent(Popover)>
</Popover>
</ActionSheet>
</ThemeProvider>
</JssProvider>
</ThemeProvider>
Expand Down
10 changes: 5 additions & 5 deletions packages/main/__karma_snapshots__/AnalyticalCard.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<JssProvider generateId={[Function]} id={{...}}>
<ThemeProvider theme={{...}}>
<WithStyles(AnalyticalCard) renderHeader={[Function: renderHeader]}>
<AnalyticalCard renderHeader={[Function: renderHeader]} classes={{...}} theme={{...}}>
<AnalyticalCard renderHeader={[Function: renderHeader]} innerRef={{...}} classes={{...}} theme={{...}}>
<div className="AnalyticalCard-card---" style={[undefined]} title={[undefined]}>
<WithStyles(AnalyticalCardHeader) title="Title" subTitle="Subtitle" arrowIndicator="Down" indicatorState="Success" value="Value" valueState="Success" unit="Unit" target="Target" deviation="Deviation" loading={false} showIndicator={true} description="Description" onHeaderPress={{...}}>
<AnalyticalCardHeader title="Title" subTitle="Subtitle" arrowIndicator="Down" indicatorState="Success" value="Value" valueState="Success" unit="Unit" target="Target" deviation="Deviation" loading={false} showIndicator={true} description="Description" onHeaderPress={{...}} classes={{...}} theme={{...}}>
<AnalyticalCardHeader title="Title" subTitle="Subtitle" arrowIndicator="Down" indicatorState="Success" value="Value" valueState="Success" unit="Unit" target="Target" deviation="Deviation" loading={false} showIndicator={true} description="Description" onHeaderPress={{...}} innerRef={{...}} classes={{...}} theme={{...}}>
<div onClick={[Function]} className="AnalyticalCardHeader-cardHeader---" title={[undefined]} style={[undefined]}>
<div className="AnalyticalCardHeader-headerContent---">
<div className="AnalyticalCardHeader-headerText---">
Expand Down Expand Up @@ -44,7 +44,7 @@
</Label>
<div>
<WithStyles(Component) renderWhitespace={false} wrapping={true} width={{...}}>
<Component renderWhitespace={false} wrapping={true} width={{...}} classes={{...}} theme={{...}}>
<Component renderWhitespace={false} wrapping={true} width={{...}} innerRef={{...}} classes={{...}} theme={{...}}>
<span style={{...}} className="Component-text---" title={[undefined]} slot={[undefined]}>
Target
</span>
Expand All @@ -60,7 +60,7 @@
</Label>
<div>
<WithStyles(Component) renderWhitespace={false} wrapping={true} width={{...}}>
<Component renderWhitespace={false} wrapping={true} width={{...}} classes={{...}} theme={{...}}>
<Component renderWhitespace={false} wrapping={true} width={{...}} innerRef={{...}} classes={{...}} theme={{...}}>
<span style={{...}} className="Component-text---" title={[undefined]} slot={[undefined]}>
Deviation
</span>
Expand All @@ -79,7 +79,7 @@
</WithStyles(AnalyticalCardHeader)>
<div style={{...}}>
<WithStyles(Component) renderWhitespace={false} wrapping={true} width={{...}}>
<Component renderWhitespace={false} wrapping={true} width={{...}} classes={{...}} theme={{...}}>
<Component renderWhitespace={false} wrapping={true} width={{...}} innerRef={{...}} classes={{...}} theme={{...}}>
<span style={{...}} className="Component-text---" title={[undefined]} slot={[undefined]}>
I&#39;m a content!
</span>
Expand Down
Loading