rich-text-editor
Version:
Rich text editor
116 lines (106 loc) • 5.06 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Toolbar;
const jsx_runtime_1 = require("react/jsx-runtime");
const styled_components_1 = __importDefault(require("styled-components"));
const add_eq_button_1 = __importDefault(require("./components/add-eq-button"));
const button_group_1 = __importDefault(require("./components/button-group"));
const extra_buttons_1 = __importDefault(require("./components/extra-buttons"));
const math_editor_buttons_1 = __importDefault(require("./components/math-editor-buttons"));
const chars = __importStar(require("./math-char-data"));
const state_1 = __importDefault(require("../../state"));
const utility_1 = require("../../utility");
/**
* When the page is resized to a small enough width, the button groups
* are aligned in a grid (instead of the default flex row). This variable
* controls the number of columns in that grid.
*/
const GRID_COLS = 3;
function Toolbar() {
const { isToolbarExpanded } = (0, state_1.default)();
return ((0, jsx_runtime_1.jsxs)(Container
// We want to hide the toolbar when the text area loses focus *except*
// when the element that causes the focus loss is the *toolabr itself*.
// To check for that, we use the `FocusEvent.relatedTarget` prop in the
// text area `onBlur`. But the toolbar container won't show up in that
// property unless it has a tab index (to make it "focusable"):
, {
// We want to hide the toolbar when the text area loses focus *except*
// when the element that causes the focus loss is the *toolabr itself*.
// To check for that, we use the `FocusEvent.relatedTarget` prop in the
// text area `onBlur`. But the toolbar container won't show up in that
// property unless it has a tab index (to make it "focusable"):
tabIndex: 0, "data-testid": "toolbar", onMouseDown: (0, utility_1.eventHandlerWithoutFocusLoss)(), children: [(0, jsx_runtime_1.jsx)(add_eq_button_1.default, {}), (0, jsx_runtime_1.jsxs)(SpecialCharacterGrid, { cols: GRID_COLS, children: [(0, jsx_runtime_1.jsx)(button_group_1.default, { isExpanded: isToolbarExpanded, cols: 13, chars: chars.BASIC, span: GRID_COLS }), (0, jsx_runtime_1.jsx)(button_group_1.default, { isExpanded: isToolbarExpanded, cols: 3, chars: chars.ALGEBRA }), (0, jsx_runtime_1.jsx)(button_group_1.default, { isExpanded: isToolbarExpanded, cols: 3, chars: chars.GEOMETRY }), (0, jsx_runtime_1.jsx)(button_group_1.default, { isExpanded: isToolbarExpanded, cols: 6, chars: chars.SET_THEORY })] }), (0, jsx_runtime_1.jsx)(extra_buttons_1.default, {}), (0, jsx_runtime_1.jsx)(math_editor_buttons_1.default, {})] }));
}
const Container = styled_components_1.default.div `
position: fixed;
top: 0;
left: 0;
width: 100%;
display: grid;
grid-template-columns: 1fr auto 1fr;
grid-template-rows: auto auto;
background-color: #fff;
box-shadow: 0 1px 10px 1px rgba(0, 0, 0, 0.2);
border-bottom: 1px solid #dfdfdf;
z-index: 10;
@media (max-width: 799px) {
grid-column: 1;
grid-row: 1;
grid-template-columns: auto auto;
grid-template-rows: auto auto;
}
`;
const SpecialCharacterGrid = styled_components_1.default.div `
display: grid;
grid-template-columns: repeat(${(props) => props.cols}, auto);
justify-items: center;
@media (min-width: 1200px) {
display: flex;
justify-content: center;
align-items: flex-start;
gap: 1em;
grid-column: 2;
grid-row: 1;
}
@media (max-width: 800px) {
grid-column: 1;
grid-row: 1;
}
`;