attribute.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // ReactJS
  9. const React = require("devtools/client/shared/vendor/react");
  10. // Reps
  11. const { createFactories, isGrip } = require("./rep-utils");
  12. const { StringRep } = require("./string");
  13. // Shortcuts
  14. const { span } = React.DOM;
  15. const { rep: StringRepFactory } = createFactories(StringRep);
  16. /**
  17. * Renders DOM attribute
  18. */
  19. let Attribute = React.createClass({
  20. displayName: "Attr",
  21. propTypes: {
  22. object: React.PropTypes.object.isRequired
  23. },
  24. getTitle: function (grip) {
  25. return grip.preview.nodeName;
  26. },
  27. render: function () {
  28. let grip = this.props.object;
  29. let value = grip.preview.value;
  30. let objectLink = this.props.objectLink || span;
  31. return (
  32. objectLink({className: "objectLink-Attr"},
  33. span({},
  34. span({className: "attrTitle"},
  35. this.getTitle(grip)
  36. ),
  37. span({className: "attrEqual"},
  38. "="
  39. ),
  40. StringRepFactory({object: value})
  41. )
  42. )
  43. );
  44. },
  45. });
  46. // Registration
  47. function supportsObject(grip, type) {
  48. if (!isGrip(grip)) {
  49. return false;
  50. }
  51. return (type == "Attr" && grip.preview);
  52. }
  53. exports.Attribute = {
  54. rep: Attribute,
  55. supportsObject: supportsObject
  56. };
  57. });