string.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. // Make this available to both AMD and CJS environments
  7. define(function (require, exports, module) {
  8. // Dependencies
  9. const React = require("devtools/client/shared/vendor/react");
  10. const { cropString } = require("./rep-utils");
  11. // Shortcuts
  12. const { span } = React.DOM;
  13. /**
  14. * Renders a string. String value is enclosed within quotes.
  15. */
  16. const StringRep = React.createClass({
  17. displayName: "StringRep",
  18. propTypes: {
  19. useQuotes: React.PropTypes.bool,
  20. style: React.PropTypes.object,
  21. },
  22. getDefaultProps: function () {
  23. return {
  24. useQuotes: true,
  25. };
  26. },
  27. render: function () {
  28. let text = this.props.object;
  29. let member = this.props.member;
  30. let style = this.props.style;
  31. let config = {className: "objectBox objectBox-string"};
  32. if (style) {
  33. config.style = style;
  34. }
  35. if (member && member.open) {
  36. return span(config, "\"" + text + "\"");
  37. }
  38. let croppedString = this.props.cropLimit ?
  39. cropString(text, this.props.cropLimit) : cropString(text);
  40. let formattedString = this.props.useQuotes ?
  41. "\"" + croppedString + "\"" : croppedString;
  42. return span(config, formattedString);
  43. },
  44. });
  45. function supportsObject(object, type) {
  46. return (type == "string");
  47. }
  48. // Exports from this module
  49. exports.StringRep = {
  50. rep: StringRep,
  51. supportsObject: supportsObject,
  52. };
  53. });