Socket
Socket
Sign inDemoInstall

storybook-addon-i18next

Package Overview
Dependencies
191
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 1.0.0

src/constants.js

167

manager.js

@@ -8,6 +8,7 @@ 'use strict';

var React = _interopDefault(require('react'));
var addons = _interopDefault(require('@storybook/addons'));
var addons = require('@storybook/addons');
var addons__default = _interopDefault(addons);
var PropTypes = _interopDefault(require('prop-types'));
var styled = _interopDefault(require('@emotion/styled'));
var components = require('@storybook/components');
var coreEvents = require('@storybook/core-events');

@@ -122,41 +123,38 @@ function _classCallCheck(instance, Constructor) {

var ADDON_ID = 'i18next';
var PANEL_ID = "".concat(ADDON_ID, "/addon-panel");
var LANGUAGE_CHANGED_EVENT_ID = 'addon:i18next:languageChanged';
var CONFIGURE_EVENT_ID = 'addon:i18next:configure';
var Container = styled.div({
padding: 15,
width: '100%',
boxSizing: 'border-box',
height: '100%',
overflow: 'auto'
});
Container.displayName = 'Container';
var Panel =
var I18NextTool =
/*#__PURE__*/
function (_React$Component) {
_inherits(Panel, _React$Component);
_inherits(I18NextTool, _React$Component);
function Panel(props, context) {
function I18NextTool(props) {
var _this;
_classCallCheck(this, Panel);
_classCallCheck(this, I18NextTool);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Panel).call(this, props, context));
_this = _possibleConstructorReturn(this, _getPrototypeOf(I18NextTool).call(this, props));
_this.state = {
isTooltipExpanded: false,
language: null,
languages: null
};
_this.configure = _this.configure.bind(_assertThisInitialized(_assertThisInitialized(_this)));
_this.emitLanguageChanged = _this.emitLanguageChanged.bind(_assertThisInitialized(_assertThisInitialized(_this)));
_this.handleLanguageSelect = _this.handleLanguageSelect.bind(_assertThisInitialized(_assertThisInitialized(_this)));
_this.configure = _this.configure.bind(_assertThisInitialized(_this));
_this.emitLanguageChanged = _this.emitLanguageChanged.bind(_assertThisInitialized(_this));
_this.handleLanguageClick = _this.handleLanguageClick.bind(_assertThisInitialized(_this));
_this.listener = function () {
var api = _this.props.api;
api.on(CONFIGURE_EVENT_ID, _this.configure);
};
return _this;
}
_createClass(Panel, [{
_createClass(I18NextTool, [{
key: "componentDidMount",
value: function componentDidMount() {
var channel = this.props.channel;
channel.on(CONFIGURE_EVENT_ID, this.configure);
var api = this.props.api;
api.on(coreEvents.SET_STORIES, this.listener);
}

@@ -166,4 +164,4 @@ }, {

value: function componentWillUnmount() {
var channel = this.props.channel;
channel.removeListener(CONFIGURE_EVENT_ID, this.configure);
var api = this.props.api;
api.off(coreEvents.SET_STORIES, this.listener);
}

@@ -184,21 +182,20 @@ }, {

value: function emitLanguageChanged() {
var channel = this.props.channel;
var api = this.props.api;
var language = this.state.language;
channel.emit(LANGUAGE_CHANGED_EVENT_ID, language);
api.emit(LANGUAGE_CHANGED_EVENT_ID, language);
}
}, {
key: "handleLanguageSelect",
value: function handleLanguageSelect(event) {
key: "handleLanguageClick",
value: function handleLanguageClick(event) {
var _this2 = this;
var language = event.target.value;
var prevLang = this.state.language;
if (prevLang !== language) {
this.setState({
language: language
}, function () {
_this2.emitLanguageChanged();
});
}
var _event$currentTarget$ = event.currentTarget.dataset;
_event$currentTarget$ = _event$currentTarget$ === void 0 ? {} : _event$currentTarget$;
var value = _event$currentTarget$.value;
this.setState({
isTooltipExpanded: false,
language: value
}, function () {
_this2.emitLanguageChanged();
});
}

@@ -208,13 +205,8 @@ }, {

value: function render() {
var active = this.props.active;
var _this3 = this;
var _this$state = this.state,
language = _this$state.language,
isTooltipExpanded = _this$state.isTooltipExpanded,
languages = _this$state.languages;
return active ? React.createElement(Container, null, React.createElement(components.Field, {
label: "Language"
}, React.createElement(components.Select, {
size: "flex",
value: language || '',
onChange: this.handleLanguageSelect
}, languages ? Object.entries(languages).map(function (_ref) {
var items = Object.entries(languages || {}).map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),

@@ -224,22 +216,38 @@ key = _ref2[0],

return React.createElement("option", {
key: key,
value: key
}, name);
}) : React.createElement("option", {
value: "",
disabled: true
}, "(No Languages)")))) : null;
return {
id: key,
title: name,
onClick: _this3.handleLanguageClick,
'data-value': key
};
});
return React.createElement(components.WithTooltip, {
placement: "top",
trigger: "click",
tooltipShown: isTooltipExpanded,
onVisibilityChange: function onVisibilityChange(t) {
return _this3.setState({
isTooltipExpanded: t
});
},
tooltip: React.createElement(components.TooltipLinkList, {
links: items
}),
closeOnClick: true
}, React.createElement(components.IconButton, {
key: "i18next",
title: "Change the language"
}, React.createElement(components.Icons, {
icon: "globe"
})));
}
}]);
return Panel;
return I18NextTool;
}(React.Component);
Panel.propTypes = {
active: PropTypes.bool.isRequired,
channel: PropTypes.shape({
I18NextTool.propTypes = {
api: PropTypes.shape({
on: PropTypes.func,
emit: PropTypes.func,
removeListener: PropTypes.func
off: PropTypes.func
}).isRequired

@@ -250,23 +258,20 @@ };

var addChannel = function addChannel(api) {
var channel = addons.getChannel();
addons.addPanel(PANEL_ID, {
title: 'i18next',
// eslint-disable-next-line react/prop-types
render: function render(_ref) {
var active = _ref.active;
return React.createElement(Panel, {
active: active,
channel: channel,
api: api
});
}
var register = function register() {
addons__default.register(ADDON_ID, function (api) {
addons__default.add(ADDON_ID, {
title: 'i18next / languages',
type: addons.types.TOOL,
match: function match(_ref) {
var viewMode = _ref.viewMode;
return viewMode === 'story';
},
render: function render() {
return React.createElement(I18NextTool, {
api: api
});
}
});
});
};
var init = function init() {
addons.register(ADDON_ID, addChannel);
};
exports.init = init;
exports.addChannel = addChannel;
exports.register = register;
{
"name": "storybook-addon-i18next",
"version": "0.1.2",
"version": "1.0.0",
"description": "React Storybook addon for i18next",

@@ -32,23 +32,28 @@ "keywords": [

"dependencies": {
"@emotion/styled": "^0.10.6",
"@storybook/addons": "^4.1.7",
"@storybook/components": "^4.1.7",
"prop-types": "^15.6.2",
"react-i18next": "^9.0.4"
"@emotion/styled": "^10.0.7",
"@storybook/addons": "^5.0.0",
"@storybook/components": "^5.0.0",
"@storybook/core-events": "^5.0.0",
"@storybook/theming": "^5.0.0",
"prop-types": "^15.7.2",
"react-i18next": "^9.0.10"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.12.1",
"eslint": "^5.15.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"rollup": "^1.1.0",
"rollup-plugin-babel": "^4.3.1",
"rollup-plugin-commonjs": "^9.2.0",
"prettier": "^1.16.4",
"rollup": "^1.4.1",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-eslint": "^5.0.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-node-resolve": "^4.0.1",
"shx": "^0.3.2"

@@ -55,0 +60,0 @@ },

@@ -96,3 +96,3 @@ 'use strict';

_this = _possibleConstructorReturn(this, _getPrototypeOf(Wrapper).call(this, props, context));
_this.changeLanguage = _this.changeLanguage.bind(_assertThisInitialized(_assertThisInitialized(_this)));
_this.changeLanguage = _this.changeLanguage.bind(_assertThisInitialized(_this));
return _this;

@@ -99,0 +99,0 @@ }

@@ -1,5 +0,1 @@

// NOTE: loading addons using this file is deprecated!
// please use manager.js and preview.js files instead
const manager = require('./manager');
manager.init();
require('./manager').register();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc