Skip to content

Commit

Permalink
Type out useStyleSet
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Sep 11, 2023
1 parent 14ff752 commit f81c2eb
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import useAdaptiveCardsPackage from '../hooks/useAdaptiveCardsPackage';
import useDisabledModEffect from './AdaptiveCardHacks/useDisabledModEffect';
import usePersistValuesModEffect from './AdaptiveCardHacks/usePersistValuesModEffect';
import useRoleModEffect from './AdaptiveCardHacks/useRoleModEffect';
import useStyleSet from '../../hooks/useStyleSet';
import useValueRef from './AdaptiveCardHacks/private/useValueRef';

const { ErrorBox } = Components;
const { useDisabled, useLocalizer, usePerformCardAction, useRenderMarkdownAsHTML, useScrollToEnd, useStyleSet } = hooks;
const { useDisabled, useLocalizer, usePerformCardAction, useRenderMarkdownAsHTML, useScrollToEnd } = hooks;

const node_env = process.env.node_env || process.env.NODE_ENV;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint react/no-array-index-key: "off" */

import { Components, hooks } from 'botframework-webchat-component';
import { Components } from 'botframework-webchat-component';
import PropTypes from 'prop-types';
import React, { FC } from 'react';
import type { DirectLineAnimationCard } from 'botframework-webchat-core';

import CommonCard from './CommonCard';
import useStyleSet from '../../hooks/useStyleSet';

const { ImageContent, VideoContent } = Components;
const { useStyleSet } = hooks;

type AnimationCardContentProps = {
actionPerformedClassName?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint react/no-array-index-key: "off" */

import { Components, hooks } from 'botframework-webchat-component';
import { Components } from 'botframework-webchat-component';
import PropTypes from 'prop-types';
import React, { FC } from 'react';
import type { DirectLineAudioCard } from 'botframework-webchat-core';

import CommonCard from './CommonCard';
import useStyleSet from '../../hooks/useStyleSet';

const { AudioContent } = Components;
const { useStyleSet } = hooks;

type AudioCardContentProps = {
actionPerformedClassName?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { hooks } from 'botframework-webchat-component';
import PropTypes from 'prop-types';
import React, { FC } from 'react';
import type { DirectLineSignInCard } from 'botframework-webchat-core';

import CommonCard from './CommonCard';

const { useStyleSet } = hooks;
import useStyleSet from '../../hooks/useStyleSet';

type SignInCardContentProps = {
actionPerformedClassName?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint react/no-array-index-key: "off" */

import { Components, hooks } from 'botframework-webchat-component';
import { Components } from 'botframework-webchat-component';
import PropTypes from 'prop-types';
import React, { FC } from 'react';
import type { DirectLineVideoCard } from 'botframework-webchat-core';

import CommonCard from './CommonCard';
import useStyleSet from '../../hooks/useStyleSet';

const { useStyleSet } = hooks;
const { VideoContent } = Components;

type VideoCardContentProps = {
Expand Down
13 changes: 13 additions & 0 deletions packages/bundle/src/hooks/useStyleSet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { hooks } from 'botframework-webchat-component';

import type AdaptiveCardsStyleSet from '../adaptiveCards/AdaptiveCardsStyleSet';

const useMinimalStyleSet = hooks.useStyleSet;

type MinimalStyleSet = ReturnType<typeof useMinimalStyleSet>[0];

export default function useStyleSet(): [MinimalStyleSet & AdaptiveCardsStyleSet] {
const [styleOptions] = useMinimalStyleSet();

return [styleOptions as MinimalStyleSet & AdaptiveCardsStyleSet];
}
4 changes: 3 additions & 1 deletion packages/bundle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import ThumbnailCardContent from './adaptiveCards/Attachment/ThumbnailCardConten
import useAdaptiveCardsHostConfig from './adaptiveCards/hooks/useAdaptiveCardsHostConfig';
import useAdaptiveCardsPackage from './adaptiveCards/hooks/useAdaptiveCardsPackage';
import useStyleOptions from './hooks/useStyleOptions';
import useStyleSet from './hooks/useStyleSet';
import VideoCardContent from './adaptiveCards/Attachment/VideoCardContent';

const renderWebChat = coreRenderWebChat.bind(null, ReactWebChat);
Expand Down Expand Up @@ -56,7 +57,8 @@ const patchedHooks = {
...hooks,
useAdaptiveCardsHostConfig,
useAdaptiveCardsPackage,
useStyleOptions
useStyleOptions,
useStyleSet
};

const AdditionalComponents = {
Expand Down
5 changes: 1 addition & 4 deletions packages/component/src/ActivityStatus/private/Originator.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import classNames from 'classnames';
import React, { memo } from 'react';

import { type ReplyAction } from '../../types/external/OrgSchema/ReplyAction';
import useStyleSet from '../../hooks/useStyleSet';

type Props = { replyAction: ReplyAction };

const Originator = memo(({ replyAction }: Props) => {
const [{ originatorActivityStatus }] = useStyleSet();
const { description, provider } = replyAction;

const text = description || provider?.name;
Expand All @@ -23,7 +20,7 @@ const Originator = memo(({ replyAction }: Props) => {
{text}
</a>
) : (
<span className={classNames('webchat__activity-status__originator', originatorActivityStatus + '')}>{text}</span>
<span className="webchat__activity-status__originator">{text}</span>
);
});

Expand Down
3 changes: 2 additions & 1 deletion packages/component/src/hooks/useStyleSet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type createStyleSet from '../Styles/createStyleSet';
import useWebChatUIContext from './internal/useWebChatUIContext';

export default function useStyleSet(): [any] {
export default function useStyleSet(): [Record<keyof ReturnType<typeof createStyleSet>, any>] {
return [useWebChatUIContext().styleSet];
}

0 comments on commit f81c2eb

Please sign in to comment.