stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
73 lines • 3.85 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AITypingIndicatorView = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useAIState2 = require("./hooks/useAIState");
var _useAnnounceOnStateChange = require("../../a11y/hooks/useAnnounceOnStateChange");
var _contexts = require("../../contexts");
var _theme = require("../../theme");
var _jsxRuntime = require("react/jsx-runtime");
var _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/AITypingIndicatorView/AITypingIndicatorView.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var AITypingIndicatorView = ({
channel: channelFromProps
}) => {
var _useTranslationContex = (0, _contexts.useTranslationContext)(),
t = _useTranslationContex.t;
var _useChannelContext = (0, _contexts.useChannelContext)(),
channelFromContext = _useChannelContext.channel;
var channel = channelFromProps || channelFromContext;
var _useAIState = (0, _useAIState2.useAIState)(channel),
aiState = _useAIState.aiState;
var _useAccessibilityCont = (0, _contexts.useAccessibilityContext)(),
announceTypingIndicator = _useAccessibilityCont.announceTypingIndicator,
enabled = _useAccessibilityCont.enabled;
var allowedStates = {
[_useAIState2.AIStates.Thinking]: t('Thinking...'),
[_useAIState2.AIStates.Generating]: t('Generating...')
};
var styles = useStyles();
var announceableState = aiState in allowedStates ? allowedStates[aiState] : null;
var shouldAnnounceTypingIndicator = enabled && announceTypingIndicator;
var typingAnnouncement = announceTypingIndicator ? announceableState : null;
(0, _useAnnounceOnStateChange.useAnnounceOnStateChange)(typingAnnouncement);
return aiState in allowedStates ? (0, _jsxRuntime.jsx)(_reactNative.View, {
accessibilityLiveRegion: shouldAnnounceTypingIndicator ? 'polite' : undefined,
accessibilityRole: "text",
style: styles.container,
children: (0, _jsxRuntime.jsx)(_reactNative.Text, {
style: styles.text,
children: allowedStates[aiState]
})
}) : null;
};
exports.AITypingIndicatorView = AITypingIndicatorView;
AITypingIndicatorView.displayName = 'AITypingIndicatorView{messageItemView{content}}';
var useStyles = () => {
var _useTheme = (0, _contexts.useTheme)(),
_useTheme$theme = _useTheme.theme,
_useTheme$theme$aiTyp = _useTheme$theme.aiTypingIndicatorView,
container = _useTheme$theme$aiTyp.container,
text = _useTheme$theme$aiTyp.text,
semantics = _useTheme$theme.semantics;
return (0, _react.useMemo)(() => {
return _reactNative.StyleSheet.create({
container: {
backgroundColor: semantics.backgroundCoreSurfaceDefault,
paddingHorizontal: _theme.primitives.spacingMd,
paddingVertical: _theme.primitives.spacingLg,
...container
},
text: {
color: semantics.textPrimary,
fontSize: _theme.primitives.typographyFontSizeMd,
fontWeight: _theme.primitives.typographyFontWeightSemiBold,
lineHeight: _theme.primitives.typographyLineHeightNormal,
...text
}
});
}, [container, text, semantics]);
};
//# sourceMappingURL=AITypingIndicatorView.js.map